Android Drive API startResolutionForResult returns RESULT_CANCELLED

I am trying to embed Google Drive in my Android application and I can’t even connect to the Api client. And I do not know why:

  • I configured the project and credentials in the developer console for ~ / .android / debug.keystore (the values ​​seem to be correct)
  • I have copied code from Drive for Android documentation → In the onConnectionFailed() method, I call connectionResult.startResolutionForResult() if connectionResult.hasResolution()
  • In onActivityResult for matching requestCode I get resultCode == 0 (RESULT_CANCELLED) even when I select my account

Do you have any idea why? I also tried adding:

 <meta-data android:name="com.google.android.apps.drive.APP_ID" android:value="----"/> 

in a manifest that is not listed on the documentation page, but on some SO posts.

thanks for the help

Edit:

I also tried using enableAutoManage

 mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .build(); 

instead of manually setting up connections and connections. Invalid callbacks:

  .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) 

It returns me error code 13 in onConnectionFailed . Based on the documentation, it seems like this is returned when:

OnConnectionFailedListener passed to enableAutoManage (FragmentActivity, GoogleApiClient.OnConnectionFailedListener) when the user does not choose to execute the resolution provided. For example, by canceling the dialog.

But I did not cancel it.

I am testing it on Nexus 5x - Android N

+5
source share
2 answers

I found where the problem was while reading something about the api wallet

I just need to create an OAuth client id, not an API

  • Go to Developer Console> Credentials
  • Click Create Credentials> OAuth Client ID> Android
  • Fill in the data
  • Create
  • Open OAuth confirmation screen (on the Credentials page)
  • Enter email name and product name
  • Save

Now it works!

+6
source

ONLY IN THE CASE

@ VizGhar's solution is correct if you skipped the process of creating a customer identifier. But I get resultCode = 0, and everything was fine with my OAuth client id. And finally, I solved it , so I created SHA1 according to the documentation, but I run my application in debug mode (build option) and always had resultCode = 0. Just switched to release mode and the problem disappeared, now resultCode = - 1 as expected.

0
source

All Articles