2013-05-05 122 views
1

我嘗試使用谷歌日曆API V3讓我的日曆,使用C#與服務佔公司給予出錯谷歌日曆API V3 C#不工作

錯誤。

以下是我的代碼。

private const string SERVICE_ACCOUNT_EMAIL = "[email protected]"; 
    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(); 

    } 

回答

-1

你的範圍應該是:

"https://www.googleapis.com/auth/" + 
Google.Apis.Calendar.v3.CalendarService.Scopes.CalendarReadonly.ToString().ToLower()