1

我正在尝试使用 Google Calendar API V3 来获取我的日历,使用 C# 和服务帐户给出错误

发送直接消息或获取响应时出错。

以下是我的代码。

    private const string SERVICE_ACCOUNT_EMAIL = "XXX@developer.gserviceaccount.com";
    private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"D:\privatekey.p12";
    static void Main(string[] args)
    {
        Test();
    }

    static void Test()
    {
        X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);

        AssertionFlowClient provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
        {
            ServiceAccountId = SERVICE_ACCOUNT_EMAIL,
            Scope = "Calendar",
        };
        var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);

        CalendarService c1 =new CalendarService(
            new BaseClientService.Initializer()
                        {
                            Authenticator = auth
                        });

        c1.Calendars.Get("MyCalenderID").Fetch();

    }
4

1 回答 1

-1

你的范围应该是:

"https://www.googleapis.com/auth/" + 
Google.Apis.Calendar.v3.CalendarService.Scopes.CalendarReadonly.ToString().ToLower()
于 2013-05-20T20:59:50.727 回答