尝试创建文件夹并设置其权限时出现以下错误。它可以在不传递文件元数据中的权限的情况下工作。
但我想创建对特定用户具有权限的文件夹,每个用户都有自己的 g-mail 帐户。我怎样才能做到这一点?谢谢!
错误信息:
编码:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DriveQuickstart
{
class Program
{
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/drive-dotnet-quickstart.json
static string[] Scopes = { DriveService.Scope.Drive };
static string ApplicationName = "Drive API .NET Quickstart";
static void Main(string[] args)
{
UserCredential credential;
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.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
Permission perm = new Permission();
perm.Type = "user";
perm.EmailAddress = "anotheruser@gmail.com";
perm.Role = "owner";
IList<Permission> perms = new List<Permission>();
perms.Add(perm);
var fileMetadata = new Google.Apis.Drive.v3.Data.File()
{
Name = "Invoices",
MimeType = "application/vnd.google-apps.folder",
Description = "Blah blah " + System.DateTime.Now.Hour + ":" + System.DateTime.Now.Minute + ":" + System.DateTime.Now.Second,
Permissions = perms
};
var request = service.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();
Console.WriteLine("Folder ID: " + file.Id);
Console.Read();
}
}
}