0
我在試下面的代碼,從他們的文檔here獲得。我無法編譯,我得到一個異常的消息:TeamDrive在谷歌驅動器API
也許我沒有正確理解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
});
在運行代碼之前,請檢查您的應用程序如何處理授權。 [Teamdrives:create](https://developers.google.com/drive/v3/reference/teamdrives/create)需要[授權](https://developers.google.com/drive/v3/reference/teamdrives/創建#auth)來運行請求。我嘗試過使用「試用此API」進行「Teamdrives:create」,並設法創建一個新的團隊雲端硬盤。 –
@ Mr.Rebot,我剛剛在我的代碼中添加了授權設置。我得到「用戶沒有足夠的權限來保存這個文件。」當使用「試用此API」時。 –
@Rebot先生,您是如何使用「試用此API」的?我已經設置了requestId,並設置了teamDrive主體的name屬性。 –