Android Drive GooglePlayServicesUtil﹕ The specified account could not be signed in

青春壹個敷衍的年華 提交于 2019-12-07 18:12:32

问题


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


回答1:


My guess is that there is a problem with the setup you did at the Developer's Console. This discussion may be helpful. – qbix

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




回答2:


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:

  • Enabled APIs: drive API
  • Credentials: Package name: 'com.blabla.yourproject', Fingerprint: '11.22.33...99'
  • Consent Screen: Email: yourmail@gmail.com , Product Name: 'YourProject'

Good Luck




回答3:


Pleas try to First normal Google account Login

mGoogleApiClient = new GoogleApiClient.Builder(this).
addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
//.addApi(Drive.API)
//.addScope(Drive.SCOPE_FILE)
.build();



回答4:


In my case cause was in incorrect 'package name' in OATH client settings: was: com.blabla.prog correct one: bla.bla.com.prog




回答5:


try to ignore the API connection by doing this:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApiIfAvailable(Drive.API)

I've done in this way and everything seems working. I really don't know why, i suppose that the Driver.API creates some problems, and doing in this way you can use the maps,the markers and all that stuff. I know that is not a good answer because i don't provide you a correct explanation, but anyway, it can help.




回答6:


This type of error may occur in following situations:

  1. If you have used release key SHA1 signing-certificate fingerprint while creating Oauth 2.0 client ID and running your application without signing it with release key (i.e. running with debug key). This is also true for debug key.
  2. If you have used different package name while creating Oauth 2.0 client ID



回答7:


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 :)



来源:https://stackoverflow.com/questions/31252524/android-drive-googleplayservicesutil-the-specified-account-could-not-be-signed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!