Google 드라이브의 일부 파일에 대한 소유자 권한을 프로그래밍 방식으로 google drive api v2를 사용하여 업데이트하려고합니다. (Google 관리 콘솔에서 '드라이브/이전 소유권'양식에 있음) 서비스 계정을 생성하고 ID를 사용하여 수퍼 관리자 계정과 결합하여 자격 증명 및 "DriveService"개체를 생성했습니다. 나와 공유 된 모든 파일을 나열하고 "File"의 "Owners"컬렉션을 열거 할 수 있습니다. 파일 (role = "writer")에 새 권한을 추가하면 정상적으로 작동합니다. 새로운 권한을 role = "owner"로 변경하려고하면 내부 오류 500이 발생합니다.Google 드라이브 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