GoogleドライブのGoogle API、C#dot netのV3を使用しています。所有者をサービスアカウントから「通常の」ドライブアカウント(同じドメイン内にある)に変更しようとすると、ドキュメント、シート、スライド(.zipや.pdfなど)以外のファイルが表示される:GoogleドライブAPI V3、ドキュメントシートとスライド以外のファイルの所有権を変更しようとしています
Error: Bad Request. User message: "You can't yet change the owner of this item. (We're working on it.).
私は、これはドキュメント、シート、スライドは記憶域のクォータでは考慮されていないという事実とは何かを持っていると思います。 (1)これは回避策がありますか? (アップロードする前にファイル名を.docに変更しようとすると、ファイルの自動ファイル変換が行われ、それ以降は役に立たない)。 (2)これは有料アカウントでも発生しますか? (3)エラーメッセージに記載されているように、Googleチームは本当に「それに取り組んでいますか?
UPDATE:
public string UploadFileToDrive(string FilePath, string ParentID)
{
try
{
Google.Apis.Drive.v3.Data.File body = new Google.Apis.Drive.v3.Data.File();
string fileNameNoPath = System.IO.Path.GetFileName(FilePath);
body.Name = "NewFile.ASC"; // some file names such as zip are not acceptable by google drive api
//body.MimeType = GoogleDriveMimeTypes.GetGenericMimeTypeString();
if (ParentID != null)
{
body.Parents = new List<string>();
body.Parents.Add(ParentID);
}
byte[] byteArray = System.IO.File.ReadAllBytes(FilePath);
System.IO.MemoryStream Ustream = new System.IO.MemoryStream(byteArray);
var requestU = _CurrentDriveService.Files.Create(body, Ustream, "");
requestU.Upload();
var uploadedFileID = requestU.ResponseBody.Id;
body.Name = fileNameNoPath;
//body.MimeType = GoogleDriveMimeTypes.GetGenericMimeTypeString();
FilesResource.CopyRequest cr = new FilesResource.CopyRequest(_CurrentDriveService, body, uploadedFileID);
var newFile = cr.Execute();
var NewFileNameID = newFile.Id;
DeleteFileFromDrive(uploadedFileID);
{
Permission p = new Permission();
p.Role = "reader";
p.Type = "anyone";
PermissionsResource.CreateRequest cc = new PermissionsResource.CreateRequest(_CurrentDriveService, p, NewFileNameID);
cc.Execute();
}
// you can comment out the next block if using Auth client
//
{
// make main account the owner in order to take its size quota in main account not google service.
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.EmailAddress = "[email protected]";
PermissionsResource.CreateRequest cc = new PermissionsResource.CreateRequest(_CurrentDriveService, p, NewFileNameID);
cc.TransferOwnership = true; // acknowledge transfer of ownership - must be set to "true" in order for role to change to "owner"
cc.Execute();
}
return NewFileNameID;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return "";
}
}
をこのコードでは、私は共有のためのすべてのファイル、変更権限をアップロードすることができますが、私はバックのGoogleドライブアカウントに所有権を変更することはできません: これは私が使用していたコードです。
コードをどのように変更しているかを表示できますか?また、この[スレッド](https://github.com/google/google-api-nodejs-client/issues/496)を最初に確認することもできます。あなたは[Permissions:update](https://developers.google.com/drive/v3/reference/permissions/update)を使って仕事をしていると書かれています。 – noogui
いくつかのコードを追加しました。 @nooguiリンクには、答えが見つからない場合はこのフォーラムへの参照がありました。これが私がここに投稿した理由です。 –