0
我已創建oAuth2 Google Drive應用程序,並在developer.gserviceaccount.com服務帳戶下創建新文件。我想將所有權更改爲擁有此服務帳戶的域中的另一個帳戶。Google Drive API更改所有權oAuth
我有新創建的文件和用戶的權限ID我想所有權轉移給的文件ID,但是當我運行:
File body;
File file;
body = new File();
body.setTitle(gdf.getTitle());
body.setDescription(gdf.getDescription());
body.setMimeType(gdf.getMime_type());
body.setUserPermission(p);
// new file gets created ok
file = d.files().insert(body).execute();
// create new permission for new user account
Permission p = new Permission();
p.setRole("owner");
p.setType("user");
p.setValue("[email protected]");
p.setId(ACCESS_DOMAIN_PERMISSION_ID); // <-- known value
d.permissions().update(file.getId(), ACCESS_DOMAIN_PERMISSION_ID, p).execute();
語句失敗抱怨不能夠找到ACCESS_DOMAIN_PERMISSION_ID。
有什麼想法?
編輯 -
無視以上 - 現在看來,我可以在域模擬用戶完成文件創建一個non-developer.gserviceaccount.com用戶:
在證書生成過程:
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(pk12)
.setServiceAccountUser(ACCESS_DOMAIN_IMPERSONATE)
.build();
該問題似乎是授權問題,可以通過授予服務帳戶的域範圍權限來解決。
會回來爲上述的成功/失敗。
你能指出我在哪裏可以找到這個Delgate域範圍的權威頁面嗎?您正在運行使用API的獨立程序,還是Google Web Development中的應用程序? 同樣的問題,但使用運行在一個服務器上的程序發送這個文件,需要改變到同一個域內的另一個用戶。但是,無法正確修改parentId,因爲它在擁有權發生更改時都會以root身份和parentId結尾。 –