我正在尝试使用Drive API在Google云端硬盘中创建新文件夹MY_FOLDER,使用快速入门示例,并在阅读Moslem Ben Dhaou时添加更多内容。
我的范围设置为:
static string[] Scopes = { DriveService.Scope.DriveFile };
我创建像这样的服务
private static void CreateService()
{
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,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Drive API service.
service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
}
根据此页面上的示例[https://developers.google.com/drive/v3/web/quickstart/dotnet,https://developers.google.com/drive/v3/web/folder],我正在创建新文件夹
var fileMetadata = new File()
{
Name = "MY_FOLDER",
MimeType = "application/vnd.google-apps.folder"
};
var request = driveService.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();
Console.WriteLine("Folder ID: " + file.Id);
我得到的错误是“权限不足[403] ”
UPDATE 我在2
的同一Google教程中创建了凭据