I am trying to integrate the Google Drive API
for Android with my Android application.
My senior created a project on the Google Developer console using the app package name and the SHA1
from my machine and generated the OAuth 2.0
client ID (I have no access to the account).
On the click of a button, I have to enable the user to access the files on Drive so as to upload them to the server.
I call the following code onClick()
:
mGoogleApiClient = new GoogleApiClient.Builder(Activity.this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(Activity.this)
.addOnConnectionFailedListener(Activity.this)
.build();
mGoogleApiClient.connect();
This calls the onConnectionFailed()
callback:
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "Connection failed");
if (connectionResult.hasResolution()) {
try {
Log.i(TAG, "Connection failed - Trying again");
connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
Log.i(TAG, "Connection failed, Code : " + connectionResult.getErrorCode());
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
}
}
The connection fails and it tries again. On retrying, it calls the onActivityResult()
and tries to connect again:
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (requestCode == Constants.RESOLVE_CONNECTION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Log.i(TAG, "Code match");
mGoogleApiClient.connect();
}
}
This time again the connection attempt fails, with error code 8 and gives the message "App is having trouble with Google Play Services. If the problem persists, please contact the developer for assistance."
I read this too: <Your App> is having trouble with Google Play services - When using GoogleApiClient, it always trigger onConnectionFailed, but did not help.
I tried looking it up on Google but nothing has helped yet. Any assistance will be great!