2017-03-15 146 views
0

我在試下面的代碼,從他們的文檔here獲得。我無法編譯,我得到一個異常的消息:TeamDrive在谷歌驅動器API

enter image description here

也許我沒有正確理解TeamDrive概念?

我不確定問題出在哪裏。下面的代碼片段,我有:

 var teamDriveMetadata = new TeamDrive() 
     { 
      Name = "Project Resources" 
     }; 

     var requestId = System.Guid.NewGuid().ToString(); 
     var request = service.Teamdrives.Create(teamDriveMetadata, requestId); 
     request.Fields = "id"; 

     var teamDrive = request.Execute(); 
     Console.WriteLine("Team Drive ID: " + teamDrive.Id); 

     Console.WriteLine("Done."); 
     Console.Read(); 

以下是身份驗證設置:

 using (var stream = 
      new FileStream("client_secret.json", FileMode.Open, FileAccess.ReadWrite)) 
     { 
      string credPath = System.Environment.GetFolderPath(
       System.Environment.SpecialFolder.Personal); 

      credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json"); 

      credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
       GoogleClientSecrets.Load(stream).Secrets, 
       Scopes, 
       "MyKey", 
       CancellationToken.None, 
       new FileDataStore(credPath, true)).Result; 
      Console.WriteLine("Credential file saved to: " + credPath); 
     } 
     // Create Drive API service. 
     var service = new DriveService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credential, 
      ApplicationName = ApplicationName 
     }); 
+1

在運行代碼之前,請檢查您的應用程序如何處理授權。 [Teamdrives:create](https://developers.google.com/drive/v3/reference/teamdrives/create)需要[授權](https://developers.google.com/drive/v3/reference/teamdrives/創建#auth)來運行請求。我嘗試過使用「試用此API」進行「Teamdrives:create」,並設法創建一個新的團隊雲端硬盤。 –

+0

@ Mr.Rebot,我剛剛在我的代碼中添加了授權設置。我得到「用戶沒有足夠的權限來保存這個文件。」當使用「試用此API」時。 –

+0

@Rebot先生,您是如何使用「試用此API」的?我已經設置了requestId,並設置了teamDrive主體的name屬性。 –

回答

1

FYI:我跑沒有問題掛鉤的示例代碼。我有一個已經建立了適當權限的測試項目。我將鏈接代碼粘貼到該項目中,並且必須解決「var request」與我現有代碼中的相同衝突。一旦解決了代碼運行沒有問題。

正如之前的建議,我會建議重點解決您的權限/範圍。