Julio
Julio

Reputation: 11

Google Drive Api stops working after publishing app in Google Play

In my app I'm using the Google Drive API but I'm getting the following message when the app is installed via 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)

My code follows the example from 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
                    });

I'm able to Sign In the user but then when trying to retrieve the files, it fails with the reason dailyLimitExceededUnreg.

I've looked at several examples such as:

I've created OAuth Tokens with the App Signing Certificate from Google Play and the SHA1 is also included in Firebase, which I've included in the project. I've created also new API Keys, the application hasn't exceeded the daily limit.

The app works locally successfully, I'm assuming due the to the debug certificate, but not sure why it is not working when downloading from Google Play.

Any suggestions?

Upvotes: 1

Views: 942

Answers (2)

Starwave
Starwave

Reputation: 2414

I had this error because of enabled minification:

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

Julio's link helds pro guard rules that fixes this issue.

Upvotes: 0

NIKHIL AGGARWAL
NIKHIL AGGARWAL

Reputation: 478

This may be due to different SHA key of your android app on Google Play. You must must have enabled Google app signing while uploading your app to playstore which results in a different SHA key of the app on playstore. You can get this SHA key from Play console. Add this key to your firebase project and app should work fine.

Upvotes: 1

Related Questions