Google OAuth 2.0 and debug key for Google Drive API

我是研究僧i 提交于 2019-11-27 06:30:46

问题


I've set up 2 Client IDs for Android application in the GoogleDriveAPI console: the first for the release APK and the second for Debug purposes. Everything ok with the released app, but my issue is only related to the second Client ID. I'm getting this exception: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException

after the following lines:

Drive.Files.List request;
request = service.files().list();
String query = "mimeType='application/vnd.google-apps.folder' AND trashed=false AND title='" + title + "' AND '" + parentId + "' in parents";
request = request.setQ(query);
com.google.api.services.drive.model.FileList files = request.execute(); // <=I'm getting the exception here

I'm using ADT on windows, I've obtained the sha1 fingerprint for debug keystore from Windows->Preferences->Android->Build for the debug mode, but the Google Drive API authorization fails! Why? The (only) solution I've found is to use the "Release" Client ID also in Debug mode, with a custom fingerprint (and that actually works).


回答1:


Try this: Take the *.apk file that isn't working (DEBUG.apk), I don't know what's your IDE, so I can't tell you where to find it, but it should be easy.

  1. Open the '*.apk' file in 7-zip or similar unzipper and find 'META-INF\CERT.RSA' file in the archive. Unzip it, for instance to your ...\desktop\
  2. Run 'keytool -printcert -file ...\desktop\CERT.RSA'.
  3. You should see the SHA1 of the APK file in question, compare it with the SHA1 you registered in the console. Double-check the package name as well. PackageName-SHA1 combination is what authorizes the app version with Google Drive.

I vaguely remember this happening to me after re-installing/upgrading my IDE or moving project to another machine (basically generating different debug SHA1 than I registered).

I know it is a long shot, but this is what I use when run into trouble. Hope it helps, Good Luck.



来源:https://stackoverflow.com/questions/28532206/google-oauth-2-0-and-debug-key-for-google-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!