Dmi*_*sev 5 android google-play-services google-drive-android-api
我正在使用Google Drive Android API(作为Google Play服务的一部分)将文件上传到云端.
要连接客户端,我使用以下代码(简化):
apiClient = new GoogleApiClient.Builder(context)
.addApi(Drive.API)
.setAccountName(preferences.getString("GOOGLE_DRIVE_ACCOUNT", null))
.build();
ConnectionResult connectionResult = apiClient.blockingConnect(SERVICES_CONNECTION_TIMEOUT_SEC, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
throw new ApiConnectionException(); //our own exception
}
Run Code Online (Sandbox Code Playgroud)
要上传文件我正在使用以下代码(简化):
DriveApi.ContentsResult result = Drive.DriveApi.newContents(apiClient).await();
if (!result.getStatus().isSuccess()) {
/* ... code for error handling ... */
return;
}
OutputStream output = result.getContents().getOutputStream();
/* ... writing to output ... */
//create actual file on Google Drive
DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi
.getFolder(apiClient, folderId)
.createFile(apiClient, metadataChangeSet, result.getContents())
.await();
Run Code Online (Sandbox Code Playgroud)
除了一个特定的用户案例外,一切都按预期工作.当用户从"已连接的应用"中删除我们的应用时(使用Google设置应用),此代码仍会返回所有调用的成功结果.虽然文件永远不会上传到Google云端硬盘.
与Google Play服务的连接也会成功.
它是API的错误还是以某种方式检测到用户断开了应用程序?
我不知道 API 的内部/外部,但是此页面可能会有所帮助https://support.google.com/drive/answer/2523073?hl=en。我会仔细检查accounts.google.com页面并验证所有权限是否都被删除。这不会解决 api 行为,但至少您可以验证权限。
| 归档时间: |
|
| 查看次数: |
1314 次 |
| 最近记录: |