George Ogden
George Ogden

Reputation: 815

Connect to Google Play Games Services Not Working

I am trying to connect to Google Play Games, but there is an error. Every time, the error unsuccessful sign in appears.

In my build.gradle (Module: app) I have this code:

dependencies {
    implementation 'com.google.firebase:firebase-core:17.2.0'
    implementation 'com.google.android.gms:play-services-games:18.0.1'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
}
apply plugin: 'com.google.gms.google-services'

At the end of my manifest, I have:

<meta-data
    android:name="com.google.android.gms.games.APP_ID"
    android:value="@string/app_id" />
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>

When I sign in using the MainActivity.java, I call this method in onResume:

private void signInSilently() {
    context = getApplicationContext();
    signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
    .requestIdToken(getString(R.string.oauth_client_id))
    .build();
    GoogleSignInAccount signedInAccount = GoogleSignIn.getLastSignedInAccount(context);
    if (GoogleSignIn.hasPermissions(signedInAccount, signInOptions.getScopeArray())) {
        account = signedInAccount;
    } else {
        client = GoogleSignIn.getClient(this, signInOptions);
        client
            .silentSignIn()
            .addOnCompleteListener(
                    this,
                    new OnCompleteListener<GoogleSignInAccount>() {
                        @Override
                        public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                            if (task.isSuccessful()) {
                                account = task.getResult();
                            } else {
                                Log.d("George", "onComplete: unsuccessful sign in");
                                //signInLoudly();
                            }
                        }
                        });
    }
}
void signInLoudly(){
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this, signInOptions);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
}

If I uncomment the signInLoudly(); method, it just goes round in an infinite loop.

Please, advise. Any help will be greatly appreciated, and if you need any more information, please, let me know.

Thanks

Upvotes: 0

Views: 196

Answers (1)

George Ogden
George Ogden

Reputation: 815

The issue was that the game was already connected to Google APIs, so I created a new game in Google Play Games that worked. I hope this helps someone with a similar issue.

Upvotes: 1

Related Questions