【问题标题】:Google Drive Api stops working after publishing app in Google Play在 Google Play 中发布应用后,Google Drive Api 停止工作
【发布时间】:2020-02-09 18:01:21
【问题描述】:

在我的应用中,我使用的是 Google Drive API,但是当通过 Google Play 安装应用时,我收到以下消息:

  com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
    {
      "code": 403,
      "errors": [
        {
          "domain": "usageLimits",
          "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
          "reason": "dailyLimitExceededUnreg",
          "extendedHelp": "https://code.google.com/apis/console"
        }
      ],
      "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
    }
        at d.f.b.a.b.d.a.b.newExceptionOnError(AbstractGoogleJsonClientRequest.java:2)
        at d.f.b.a.b.d.a.b.newExceptionOnError(AbstractGoogleJsonClientRequest.java:1)
        at d.f.b.a.b.d.b.a(AbstractGoogleClientRequest.java:5)
        at d.f.b.a.c.p.a(HttpRequest.java:88)
        at d.f.b.a.b.d.c.executeUnparsed(AbstractGoogleClientRequest.java:3)
        at d.f.b.a.b.d.c.executeUnparsed(AbstractGoogleClientRequest.java:1)
        at d.f.b.a.b.d.c.execute(AbstractGoogleClientRequest.java:1)

我的代码遵循Google中的示例:

final GoogleAccountCredential credential =
                GoogleAccountCredential.usingOAuth2(
                        this, Collections.singleton(DriveScopes.DRIVE_FILE));
        credential.setSelectedAccount(googleAccount.getAccount());
        final Drive googleDriveService =
                new Drive.Builder(
                        AndroidHttp.newCompatibleTransport(),
                        new GsonFactory(),
                        credential)
                        .setApplicationName(getString(R.string.app_name))
                        .build();

        mDriveServiceHelper = new DriveServiceHelper(googleDriveService);

mDriveServiceHelper.queryFiles()
                    .addOnSuccessListener(fileList -> {
                    // Logic to load the data

                    })
                    .addOnFailureListener(exception -> {
                        Log.e(TAG, "Unable to query files.", exception);
                        // This is where it fails
                    });

我可以让用户登录,但在尝试检索文件时失败,原因是 dailyLimitExceededUnreg

我看过几个例子,例如:

我已经使用来自 Google Play 的 App Signing Certificate 创建了 OAuth 令牌,并且 SHA1 也包含在我已包含在项目中的 Firebase 中。我还创建了新的 API 密钥,应用程序没有超过每日限制。

该应用程序在本地成功运行,我假设由于调试证书,但不确定为什么从 Google Play 下载时它无法运行。

有什么建议吗?

【问题讨论】:

标签: android google-drive-api certificate sha1 google-drive-android-api


【解决方案1】:

这可能是由于您的 Android 应用在 Google Play 上的 SHA 密钥不同。您必须在将应用上传到 Playstore 时启用 Google 应用签名,这会导致 Playstore 上的应用使用不同的 SHA 密钥。您可以从 Play 控制台获取此 SHA 密钥。将此密钥添加到您的 firebase 项目,应用程序应该可以正常工作。

【讨论】:

  • 在 Google Play 上哪里可以找到 SHA 密钥?对于开发,我从密钥库中获取 SHA 密钥,但这些密钥不适用于生产......但是为什么?
【解决方案2】:

由于启用了缩小,我遇到了这个错误:

        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

Julio 的链接包含修复此问题的专业保护规则。

【讨论】:

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