我正在尝试从他们的文档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
});
答案 0 :(得分:1)
仅供参考:我运行的示例代码没有问题。我有一个已经建立了适当权限的测试项目。我将链接的代码粘贴到该项目中,并且必须在现有代码中解决与“ var request ”冲突的问题。一旦解决,代码就会毫无问题地运行。
如前所述,我建议您专注于解决您的权限/范围。