【问题标题】:cannot upload to google drive from my android app com.google.android.gms.auth.GoogleAuthException: Unknown无法从我的 android 应用程序 com.google.android.gms.auth.GoogleAuthException 上传到谷歌驱动器:未知
【发布时间】:2014-01-21 16:42:39
【问题描述】:

我正在编写一个用于上传所选图片的安卓应用

到用户的谷歌驱动器。

我已经将代码从git克隆到另一台机器,然后图像将不再上传。

我得到一个com.google.android.gms.auth.GoogleAuthException: Unknown 异常。但它被抓住了:

 } catch (IOException e) {
          e.printStackTrace();
        }

      if(fileContent.length() > 5 * 1024 * 1024)
      {
          // Resumable Uploads when the file size exceeds a file size of 5 MB.
          // check link : 
          // 1) https://code.google.com/p/google-api-java-client/source/browse/drive-cmdline-sample/src/main/java/com/google/api/services/samples/drive/cmdline/DriveSample.java?repo=samples&r=08555cd2a27be66dc97505e15c60853f47d84b5a
          // 2) http://stackoverflow.com/questions/15970423/uploading-downloading-of-large-size-file-to-google-drive-giving-error

          AbstractGoogleClientRequest<File> insert = mDriveService.files().insert(body, mediaContent);
          MediaHttpUploader uploader = insert.getMediaHttpUploader();
          uploader.setDirectUploadEnabled(false);
          uploader.setProgressListener(new FileUploadProgressListener());
          destFile = (File) insert.execute();

      }   
      else
      {
          // Else we go by Non Resumable Uploads, which is safe for small uploads.
          destFile = mDriveService.files().insert(body, mediaContent).execute();
      }

这是我的登录驱动代码

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(DriveScopes.DRIVE));
    startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);

    Intent intent = getIntent();

}

  @Override
  protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_ACCOUNT_PICKER:
      if (resultCode == RESULT_OK && data != null && data.getExtras() != null) {
        String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        if (accountName != null) {
          credential.setSelectedAccountName(accountName);
          mDriveService = getDriveService(credential);
          saveFileToDrive();
        }
      }
      break;

      //second try to upload, if credentials were wrong
    case REQUEST_AUTHORIZATION:
      if (resultCode == Activity.RESULT_OK) {
        saveFileToDrive();
      } else {
        startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
      }
      break;
    case CAPTURE_IMAGE:
      if (resultCode == Activity.RESULT_OK) {
        saveFileToDrive();
      }
    }
  }

我可以检查和验证的任何提示(可能缺少库引用?)

我以为是因为我从外部 SD 上传图像,但即使我从本地手机 SD 中选择它也会引发相同的异常

【问题讨论】:

  • 您在哪里登录 Google 云端硬盘?
  • 您确实确定您的凭据是正确的并且您首先初始化了您的 mDriveService?
  • 他们怎么会错?我选择在官方应用程序中工作的驱动器帐户。这是我初始化mDriveService的第一个也是唯一的地方

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


【解决方案1】:

问题是我必须重新注册我的应用程序

为创建和签署 apk 的新机器使用新的 SHA1 密钥

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    相关资源
    最近更新 更多