I need to use the drive api to create a file with some content from my app, so I followed the "Getting Started" section from Drive api web page.
So I enabled the api on my developer´s console, created an OAuth client id as it says. (Can I use the api if I haven´t paid the 2$5 yet?)
On my settings activity on the onCreate method I'm doing:
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
I'm implementing the methods:
@Override
protected void onStop(){
getGoogleApiClient().disconnect();
super.onStop();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, resolvingError);
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (resolvingError) {
// Already attempting to resolve an error.
return;
}else if (connectionResult.hasResolution()) {
try {
resolvingError = true;
connectionResult.startResolutionForResult(this,RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
getGoogleApiClient().connect();
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
resolvingError = true;
}
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if(requestCode == RESOLVE_CONNECTION_REQUEST_CODE) {
resolvingError = false;
if (resultCode == RESULT_OK) {
if(!getGoogleApiClient().isConnecting() && !getGoogleApiClient().isConnected()){
getGoogleApiClient().connect();
}
}
}
}
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "Success!!! :D :D", Toast.LENGTH_SHORT).show();
}
@Override
public void onConnectionSuspended(int i) {}
Then I call googleApiClient.connect(); on a button onclick method.
I'm getting the select account google drive dialog, select an account and press OK, and I'm getting this error on the connection result:
E/GooglePlayServicesUtil﹕ The specified account could not be signed in.
I searched over the web and cant find the cause of this problem.... maybe I'm doing something wrong on the developers's console... don't know...
UPDATE:
So i delete the project on Google developer´s console and create it again, i also add the Drive Api and enable it, i added a product name on authorization screen, and a new client id with my package name and sha1 id...
also update my manifest,
added to manifest tag:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
to application tag:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
to the activity tag where im doing the connection:
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="id=<app id i took this id from developers´console>" />
<action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
<data android:mimeType="application/vnd.google-apps.drive-sdk.<app id>" />
i also building a signed apk using the debug keystore to test my app. (on real device).
after all this the error is still rising...
Pleas try to First normal Google account Login
Here's my usual checklist:
1/ get the APK in question, push it through an unzipper, like 7-zip. you'll find a folder META-INF with a file CERT.RSA. Get it.
2/ run 'keytool -printcert -file ......\CERT.RSA' and copy/save the SHA1 '11.22.33...99'
3/ get you package name (from manifest?) 'com.blabla.yourproject'
4/ open developers console 'https://console.developers.google.com/project'
5/ in your project, check:
Good Luck
hello, reading the discussion qbix mention above i just found the cause of my problem...
the default flavor at my project structure had an incorrect Application id, i just change it to my app package "com.xxxxx.yyyyy".
so i beleave when googleApiClient attempted to connect, find diferent package name at id client credencials and deny access....
now is working fine thanx....
Another thing that can go wrong is that you create credentials for "API Key" instead of "OAuth 2.0 client ID".
Yeah silly I know.. guide says "Client ID" so I guess I went by the length of the string :)
This type of error may occur in following situations:
In my case cause was in incorrect 'package name' in OATH client settings: was: com.blabla.prog correct one: bla.bla.com.prog