我嘗試使用谷歌驅動API更新谷歌驅動的一些文件的所有者許可v2的編程方式。(如谷歌管理控制檯做的「驅動器/轉讓所有權」的形式) 我創建了一個服務帳戶,並使用其ID與超級管理員帳戶結合創建憑證和「DriveService」對象。 我能夠列出與我共享的所有文件並枚舉「文件」的「所有者」集合。向文件添加新權限(role =「writer」)可以正常工作。如果我嘗試新的權限更改爲角色=「所有者」我得到一個內部錯誤500谷歌雲端硬盤API/SDK,使用服務帳戶更改所有權人未
沒有任何人看到這樣的錯誤之前和我怎麼能解決?
這是我的代碼:
// ---------------------- BUILD CREDENTIALS -------------------------------
Google.Apis.Auth.OAuth2.ServiceAccountCredential m_Creds = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(<MY_SERVICE_ACCOUNT>)
{
Scopes = new[]
{
DriveService.Scope.Drive,
DriveService.Scope.DriveFile,
DriveService.Scope.DriveAppdata
}
,
User = <MY_ADMIN_ACCOUNT>
}.FromCertificate(certificate));
// ---------------------- BUILD CLIENTINIT -------------------------------
var myCInit = new BaseClientService.Initializer
{
ApplicationName = "Testapplication",
HttpClientInitializer = m_Creds
};
string myAccountname = "Test User1"; // accountname to look for
string myNewAccountEmail = "[email protected]"; // email of new owner account
// ---------------------- DRIVE SERVIVE CREATION -------------------------------
var myDService = new DriveService(myCInit);
// ----------------------- GET THE FILE LIST------------------------------------
var myFList = myDService.Files.List().Execute();
foreach (Google.Apis.Drive.v2.Data.File currF in myFList.Items)
{
foreach (Google.Apis.Drive.v2.Data.User currUser in currF.Owners)
{
if (currUser.DisplayName.StartsWith(myAccountname))
{
// create new permission for new owner
Permission p = new Permission();
p.Role = "writer";
p.Type = "user";
p.Value = myNewAccountEmail;
myDService.Permissions.Insert(p, currF.Id).Execute(); // works fine, creates new permission
// get permission id
var myNewID = myDService.Permissions.GetIdForEmail(myNewAccountEmail).Execute();
// get my newly created permission
p = myDService.Permissions.Get(currF.Id, myNewID.Id).Execute();
p.Role = "owner";
// create update request
var myUpdR = myDService.Permissions.Update(p, currF.Id,myNewID.Id);
myUpdR.TransferOwnership = true; // yes, we want to be an owner
myUpdR.Execute(); // this call gets an "internal error 500"
}
}
}
任何幫助表示讚賞。
Thx。 TL
在我的測試用戶都在同一個域中。這些文檔是共享的,管理員用戶可以看到並更改它。 「所有權變更」僅以「內部錯誤」結束。 – R2D2