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...