2013-07-17 54 views
1

我正在使用下面的一段代碼來獲取帶有服務帳戶的文件。Google Drive API 1.4錯誤:發送直接消息或獲取響應時出錯

 var certificate = new X509Certificate2("D:\\05-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable); 
     var privateKey = certificate.Export(X509ContentType.Cert); 
     var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) 
     { 
      ServiceAccountId = "[email protected]account.com", 
      Scope = DriveService.Scopes.Drive.GetStringValue(), 
      ServiceAccountUser = "[email protected]" 
     }; 
     var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState); 
     DriveService service = new DriveService(new BaseClientService.Initializer() 
     { 
      Authenticator = auth, 
      ApplicationName = "My APP", 
     }); 

     FilesResource.ListRequest request = service.Files.List(); 
     FileList files = request.Execute(); 

這裏執行()API是給異常

錯誤在發送直接消息或獲取 響應發生。

編輯:項目是基於提到@https://code.google.com/p/google-api-dotnet-client/wiki/Build

編輯2的設置:我有一個基於服務帳戶

+0

您是否瀏覽了https://developers.google.com/drive/delegation上介紹的代表團? –

+0

感謝Burcu, 它開始工作.... 我創建了一個新的Google APP帳戶,並提到了@ https://developers.google.com/drive/delegation設置。但我認爲它需要一些時間生效.... :-) – Jeevan

+0

很高興知道它現在工作。 –

回答

0

我有同樣問題的cPanel正確的設置。我最終得到了它的工作;我有一些錯誤。

  1. 我去Google Cloud Console和再生和下載我的密鑰文件。轉到API & auth->註冊的應用程序。
  2. 我放入provider對象的唯一屬性是.ServiceAccountId.Scope
  3. 我必須用實際範圍替換Scope,而不是使用枚舉值(這只是一個問題,因爲我使用的是VB)。我在Fusion Tables中工作,範圍渲染爲「Fusiontables」,因爲VB.NET不使用枚舉函數GetStringValue()。現在我正在使用"https://www.googleapis.com/auth/fusiontables"。請去here查看有效範圍的列表。
  4. 對於ServiceAccountId,我使用了服務帳戶「電子郵件地址:」和「@」。 ([email protected]),而不是在控制檯(12345.apps.googleusercontent.com)中標記爲「客戶端ID:」的那個。

希望這可以幫助別人。

相關問題