【发布时间】:2014-04-04 09:54:34
【问题描述】:
我正在努力让我的代码正常工作。
我希望我的应用程序(单击按钮时)显示驱动器根文件夹中的所有文件夹(和文件)。 但这似乎是不可能的,因为即使我已经使用 Ouath2 授权了该应用程序,该应用程序也只能访问用户选择的文件和文件夹。
这种行为很奇怪,因为当文件夹选择器打开时,如果内容是文件夹,它只会列出该文件夹的内容。它根本不会列出任何文件。
能否请专家查看我的代码并告诉我哪里出错了?
我正在使用PickFolderWithOpener 活动,以获取driveId。它根据用户从选择器中的选择返回一个驱动器ID。
DriveId driveId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
这就是这里返回的文件夹 Drive ID 吗?然后我需要调用意图ListFilesInFolderActivity。我假设我必须在意图调用中传递这个 driveID?如果我将 DriveID 格式化为字符串并传递它,它会失败
带有“找不到 DriveId。您有权查看此文件吗?”消息。
所以我正在做的是传递 ResourceID。
Intent intent = new Intent(this, ListFilesInFolderActivity.class);
intent.putExtra("DriveID", driveId.getResourceId());
startActivity(intent);
ListFilesInFolderActivity?中需要用到什么DriveID或resourceID?这是我在ListFilesInFolderActivity?中的内容
Bundle extras = getIntent().getExtras();
folderId= extras.getString("DriveID"); // this is the resourceID
Drive.DriveApi.fetchDriveId(getGoogleApiClient(), folderId)
.setResultCallback(idCallback);
final private ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
@Override
public void onResult(DriveIdResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Cannot find DriveId. Are you authorized to view this file?");
return;
}
DriveFolder folder = Drive.DriveApi.getFolder(getGoogleApiClient(), result.getDriveId());
showMessage("Result driveId is: " + result.getDriveId());
folder.listChildren(getGoogleApiClient())
.setResultCallback(metadataResult);
}
};
这似乎有效,但它只列出所选文件夹中的文件夹。它没有列出文件。
为什么folder.listChildren(getGoogleApiClient()) 也没有列出文件!?
希望这是我明显缺少的东西。
【问题讨论】:
-
您的应用中的云端硬盘范围是什么?
-
mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build();
-
这是为什么? "注意:Google Drive Android API 目前仅支持 drive.file 和 drive.appdata 授权范围。如果您的应用程序需要 Drive Android API 中尚不可用的其他权限或功能,您必须使用 Google APIs Java Client。"跨度>
-
尝试
DriveScopes.DRIVE看看是否列出了文件。类似credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE)); -
我收到错误:无法解析符号 DriveScopes。只有驱动器。我正在使用这个 Google API:developers.google.com/drive/android
标签: android google-api google-drive-api google-drive-android-api