【问题标题】:Google Drive Api can't open all file formatsGoogle Drive Api 无法打开所有文件格式
【发布时间】:2017-11-27 19:31:55
【问题描述】:

您好,我尝试使用 Google Drive Api 在 Android 应用中打开 Google Drive 中的一些文件:

ResourceClient.openFile(selectedFile.asDriveFile() , DriveFile.MODE_READ_WRITE)

我的代码在 Word 格式 (docx) 上工作得很好,但对于所有其他格式我都试过了

com.google.android.gms.common.api.ApiException: 10: 此文件不可打开。

异常。这个例外无处可寻,我真的无法摆脱它。如果有人可以提供帮助,我将不胜感激。

编辑:顺便说一句。我已成功声明所有文件的元数据。

编辑 2:即使在使用 Google 示例时,我也只能打开 Word 文档。

我使用的代码以防您需要它:

登录谷歌:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(Drive.SCOPE_FILE)
                .build();
        signInClient = GoogleSignIn.getClient(getApplicationContext(), gso);
        startActivityForResult(signInClient.getSignInIntent(), SING_IN_REQEST_CODE);

获取元数据和文件:

contentsTask = resourceClient.getMetadata(selectedFile.asDriveResource())
    .continueWithTask(new Continuation<Metadata, Task<DriveContents>>(){
        @Override
        public Task<DriveContents> then(@NonNull Task<Metadata> task) throws Exception {
            if(task.isComplete() && task.isSuccessful()) {
                Log.d(TAG, "Metadata claimed sucessfully");
                if(task.getResult().isEditable())
                    Log.d(TAG, "File is edittable");
                return resourceClient.openFile(selectedFile.asDriveFile() , DriveFile.MODE_READ_WRITE);
            }
            else {
                Log.i(TAG, "Metadata wasn't claimed sucessfully" + task.isComplete());
                return null;
            }
        }
    } ).addOnSuccessListener(new OnSuccessListener<DriveContents>() {
                @Override
                public void onSuccess(DriveContents driveContents) {
                    Log.i(TAG, "successfully get driveContents");
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.i(TAG, "didn't successfully get driveContents", e);
                }
            });

编辑:问题已被复制:https://github.com/googledrive/android-demos/issues/70

【问题讨论】:

  • Drive API 无法打开各种文件。您可以在Supported MIME Types 中看到大多数受支持的类型。在here 中发现了一些据称未记录的文件类型。
  • 非常感谢 MαπμQμαπkγVπ.0 的帮助。为什么我必须指定要打开的 MIME 类型?
  • 我无法打开仅包含在列表中的文件,这很矛盾

标签: java android google-api google-drive-api google-drive-android-api


【解决方案1】:

所以,我离开并再次回到这个话题 2 次,但对于其他人:尽管我没有找到任何可以说 Android Drive API 的文档(我的朋友告诉我与 Java API 完全相同的经验) ) 只能下载文件:

  • PDF
  • 图片

无法下载:

  • 办公格式

如果有人有什么要补充的(比如我忽略了关于主题格式的大量文档,您能否使用 Drive API 访问,请告诉我。-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多