Search code examples
javaandroidapidrive

Google Drive API Android: stuck on login


I'm trying to implement the Drive API for Android to back-up a file to the AppFolder. I'm using the tutorial on Using the Google APIS Client Library for Java to integrate with Drive on Android and used some code snippets from the Quickstart.

  • When opening the activity with the drive API calls (like in this Activity from the Quickstart, the .connect() call is unsuccesful with error code SIGN_IN_REQUIRED, which seems logical to me.
  • I then proceed to login to my Google account. The login looks succesfull.
  • The activity gets resumed. As in the linked Activity file from the Quickstart, the onResume method calls .connect() again.
  • The .connect() call fails with the same error code (SIGN_IN_REQUIRED) and the process repeats.

In the API Manager of the Google Developer Console, I created a project for this app. In that project, I created an "OAuth 2.0 client ID" for the app with the debug package name and the SHA-1 for the debug key. In the manifest of the Quickstart, I didn't see the Client ID of said credential used anywhere.

Is this a known issue or did I make a mistake somewhere?

Edit:

I built the original Quickstart from scratch, and the error still occurred. It might therefore be an issue with the API Console rather than a client issue.

  • I've created a project for the app.
  • I've enabled the Drive API and Google+ API.
  • I've created an "API Key" credential with the package name of my application and SHA-1 of my debug signing key.

Solution

  • Not the solution I was expecting but here it is:

    It turned out Android Studio was NOT signing my app with the debug key located at ~/.android/debug.keystore, but with a different key.

    Without knowing which key it was, I was able to figure out its SHA-1 using the method described in this SO question.