【问题标题】:Unable to overwrite files in Google Drive AppData folder INTERNAL_ERROR无法覆盖 Google Drive AppData 文件夹中的文件 INTERNAL_ERROR
【发布时间】:2017-07-31 01:44:57
【问题描述】:

我在我的应用程序中使用GDAA 来管理我在谷歌驱动器中的应用程序文件。下面列出的所有操作都可以正常工作,例如

  • google 登录(为 AppData 文件夹添加范围)
  • AppData Folder下载文件
  • 上传文件到AppData Folder
  • AppData Folder删除文件

但是当我尝试覆盖AppData Folder 中的文件时,我在onResult() 回调中收到以下错误

Status Message : Failed to commit changes. 
Status Code : INTERNAL_ERROR (8)

我无法理解为什么会这样。请在下面找到我的代码以供参考

public void overwrite(String strLocalFilePath, String strDriveId, String strGoogleDriveFileMimeType, String strGoogleDriveFileTitle){
    final DriveId driveId = DriveId.decodeFromString(strDriveId);
    DriveFile file = driveId.asDriveFile();

    file.open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
        @Override
        public void onResult(DriveApi.DriveContentsResult result) {
            if (!result.getStatus().isSuccess()) {
                Log.e(TAG,"Error");
                return;
            }

            DriveContents driveContents = result.getDriveContents();
            OutputStream outputStream = driveContents.getOutputStream();
            boolean isSuccess = writeFileToStream(outputStream, strLocalFilePath);

            if (isSuccess) {
                MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                        .setTitle(strGoogleDriveFileTitle)
                        .setMimeType(strGoogleDriveFileMimeType)
                        .build();

                ExecutionOptions executionOptions = new ExecutionOptions.Builder()
                        .setNotifyOnCompletion(true)
                        .setTrackingTag("SAMPLE_TRACKING_TAG")
                        .build();

                driveContents.commit(mGoogleApiClient, changeSet, executionOptions).setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        // Handle the response status
                        if (!status.getStatus().isSuccess()) {
                            Log.e(TAG, "Error while trying to overwrite file. Message : "+status.getStatus().getStatusMessage() + " Status code : "+status.getStatus().getStatusCode());
                            return;
                        }else{
                            Log.d(TAG,"File overwritten successfully!!");
                        }

                    }
                });
            } else {
                Log.e(TAG, "File I/O Error occurred : "+ strGoogleDriveFileTitle);
            }
        }
    });
}

private boolean writeFileToStream (OutputStream oos, String filePath){
    if (oos != null) {
        InputStream is = null;
        try {
            Log.d(TAG, "Started writing file : "+filePath);
            is = new FileInputStream(filePath);
            byte[] buf = new byte[4096];
            int c;
            while ((c = is.read(buf, 0, buf.length)) > 0) {
                oos.write(buf, 0, c);
                oos.flush();
            }
            Log.d(TAG, "Finished writing file : "+filePath);
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if(oos != null) {
                    oos.close();
                }
                if(is != null){
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
    }
    return false;
}

【问题讨论】:

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


    【解决方案1】:

    根据thread,如果您收到错误代码 8 (INTERNAL_ERROR),请在开发控制台中仔细检查您的应用注册。请注意,每个注册的 Android 客户端都由(包名称,Android 签名证书 SHA-1)对唯一标识。如果您的调试和生产环境有多个包名称/签名证书,请确保注册每一对。

    验证:

    1. 打开Credentials page 并选择您的项目
    2. 确保每一对都有一个 Android 类型的 OAuth 2.0 客户端 ID。 要为您的 Android 客户端创建新的 OAuth 2.0 客户端 ID,请从下拉列表中选择 New Credentials->OAuth2 Client ID,选择 Android 并输入您的包名称/签名证书指纹在那里。

    获取您的签名密钥证书 SHA-1:

    标准调试密钥

    keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
    

    其他(自定义)键

    keytool -list -v -keystore $YOUR_KEYSTORE_LOCATION
    

    这是一个可能也有帮助的参考:

    如果您在 1) 确保您已使用相应的证书指纹注册了包名称,并且 2) 正在(重新)使用已经存在的项目之后仍遇到此错误,那么您应该检查该项目是否具有产品名称和与之关联的电子邮件地址(仔细检查那个),两者都可以在“同意屏幕”部分中找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多