Google Drive Android API "connection failed"

I am trying to work with Google Drive Google on Android, using the demo first:

https://github.com/googledrive/android-quickstart

However, I have this error that I cannot solve.

Failed to connect to GoogleApiClient: ConnectionResult {StatusCode = SIGN_IN_REQUIRED, resolution = PendingIntent {421d40e8: android.os.BinderProxy@42137f78 }}

@Override public void onConnectionFailed(ConnectionResult result) { // Called whenever the API client fails to connect. Log.i(TAG, "GoogleApiClient connection failed: " + result.toString()); if (!result.hasResolution()) { // show the localized error dialog. GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show(); return; } // The failure has a resolution. Resolve it. // Called typically when the app is not yet authorized, and an // authorization // dialog is displayed to the user. try { result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION); } catch (SendIntentException e) { Log.e(TAG, "Exception while starting resolution activity", e); // There was an error with the resolution intent. Try again. mGoogleApiClient.connect(); } } @Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == REQUEST_CODE_RESOLUTION) { if (resultCode == RESULT_OK) { Log.i(TAG, "Error resolution success."); // Make sure the app is not already connected or attempting to connect if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) { mGoogleApiClient.connect(); } } else { GooglePlayServicesUtil.getErrorDialog(requestCode, this, 0).show(); } break; } } 
+6
source share
4 answers

This may be due to negligence on the part of the developer (as it happened to me). The SHA1 information you provide on the console is a production key, and you are testing Debug mode (SHA1 details will vary). The Google API error message for drives might have been better!

+3
source

Here is the error information you receive. I assume you are, but you need to be logged in to access Drive. When I run the sample application, at the very beginning it asks me to choose an account. Perhaps you do not have an account synchronized with the device that you are using? There is an โ€œadd accountโ€ option, but perhaps the behavior is different from when you have zero accounts. The documentation assumes that you either continue to work without using the API (simply because you cannot, if you do not subscribe), or call startResolutionForResult(Activity, int) to invite the user to log in, but it would probably be easiest to add account on your device .

+2
source

You can send my answer here fooobar.com/questions/978468 / ... to connect to google account, this only works fine in signed apk

then you can go to Google Drive

  IntentSender intentSender = Drive.DriveApi .newOpenFileActivityBuilder() .build(mGoogleApiClient); try { startIntentSenderForResult(intentSender, DRIVE_CHOOSER_REQUEST, null, 0, 0, 0); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); } 
+1
source

Not sure if anyone else needs this, but in my case I had two Google accounts, so I first need to choose which account I want to use. I used this code in onConnectionFailed

  if (!connectionResult.hasResolution()) { // show the localized error dialog. GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), mContext, 0).show(); return; } try { connectionResult.startResolutionForResult(mContext, 1); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); } 
0
source

Source: https://habr.com/ru/post/978463/


All Articles