question

dan avatar image
dan asked

Having trouble with LinkGoogleAccount. Any help appreciated!

Hi there.

I am trying to use LinkGoogleAccount to link a Google Play Games account to the user's PlayFab account.

I think I have jumped through all the pre-requisite hoops, but I guess I must be missing something, because when I try to link, I get the following Error Message:

Google API error code: invalid client details: unauthorized


What I am doing:

  • I am getting an oAuth token from the signed-in Google Play Games account.
  • My app is linked, and the Google Play Games API's are active
  • I activated the Google add-on for PlayFab
  • I am using the autognerated web client oAuth credentials for this add-on

I get the feeling I am missing something...

Any suggestions are most welcome.

Thanks,

Dan

apisAccount ManagementPartner Add-onsgame manager
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dan avatar image dan commented ·

One more thing!

The scope for the oAuth Token I am using is
oauth2:https://www.googleapis.com/auth/games
...
is that correct?

0 Likes 0 ·
dan avatar image dan commented ·

Also, should the oAuth secret in my add-on set-up be a 24(ish) character string, or a loooong JSON entry?

0 Likes 0 ·
dan avatar image dan commented ·

OK then! Looks like it was a combination of a few things... I'm still not there though, but at least now I am getting a different error message! Here is what I updated..

  1. Made sure my oAuth token had the three scopes listed above.
  2. Used the correct oAuth secret key (the string, not the JSON)
  3. Added authorised JavaScript Origins and Redirect URIs in my Google API settings
    https://blog.playfab.com//blog/setting-up-google-sign-in

So now I get a totally new error: Google API error code: invalid grant details: already redeemed.

Suggestions?

Thanks,
Dan

0 Likes 0 ·
dan avatar image
dan answered

OK, so.. I have this working... but it still doesn't work!

Allow me to elaborate (so that future developers can avoid my mistakes, and maybe someone can help me out!)

Firstly I was getting this error:

Google API error code: invalid client details: unauthorized

This was caused by incorrect set up on the Google Dev Console and Playfab.

To fix this I did the following:

  1. Made sure my oAuth token had the right scopes:
    - https://www.googleapis.com/auth/games
    - profile
  2. Used the correct oAuth secret key - the 24(ish) character string, not the JSON
  3. Added authorised JavaScript Origins and Redirect URIs in my Google API settings
    https://blog.playfab.com//blog/setting-up-google-sign-in
  4. Made sure the PlayFab Google add-on was configured to use the Client ID and Client Secret for a Web App - not an Android app!

This worked a little better, and gave me this error:

Google API error code: invalid grant details: already redeemed.

This is caused by a sending a token or code that has been used up. So I waited a bit and tried again. Different error:

Google API error code: invalid grant details: Incorrect token type.

This error is caused by sending an Access Token instead of an Authorization Code. Or vice versa.

Now, according to this documentation LinkGoogeAccount can take either... but for some reason the PlayFab Unity SDK implementation of LinkGoogleAccount doesn't support Access Tokens... so I added it manually...

    public class LinkGoogleAccountRequest : PlayFabRequestCommon
    {
        /// <summary>
        /// Server authentication code obtained on the client by calling getServerAuthCode() (https://developers.google.com/identity/sign-in/android/offline-access) from Google Play for the user.
        /// </summary>
        public string ServerAuthCode;
        /// <summary>
        /// Added by Dan.
        /// </summary>
        public string AccessToken;
        /// <summary>
        /// If another user is already linked to the account, unlink the other user and re-link.
        /// </summary>
        public bool? ForceLink;
    }

...which let me use my Access Token to link the accounts.

Finally it worked - I am getting a successful result when I call LinkGoogleAccount.

However, when I check the Player Data on PlayFab, no Google account has been linked - I can only see the Android device and linked Facebook account (which I successfully linked earlier):

So does anyone know why I am getting a successful response without any account linking actually having happened?

Thanks,

Dan


6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Actually, the recommended login path is to use the ServerAccessCode, and not the AccessToken (https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google). We updated to the newer model a little while ago, and will eventually deprecate the AccessToken (though it will continue to work for live titles).

The link appearing in the Game Manager may be a distinct issue. Can you try getting the player info via GetUserAccountInfo or GetAccountInfo, and see if it's there?

1 Like 1 ·
dan avatar image dan commented ·

Thanks for the info, Brendan.
I checked user data using Postman, and the accounts ARE actually linking, they are just not showing up in the back-end. :(

Unfortunately the plug-in I am using to get the Access Token does not have a clear way to get an appropriate Auth. Code - I will investigate!

Cheers,
Dan

0 Likes 0 ·
brendan avatar image brendan dan commented ·

Thanks for confirming - the accounts being updated in the Game Manager is as a result of events in PlayStream. There's a known issue with certain link/unlink paths that aren't generating the correct event. We're investigating and will be updating soon with a fix for this.

0 Likes 0 ·
dan avatar image dan commented ·

Thanks for the update, Brendan.

With a little help from the support team of the plug-in I am using, I found an easy (but oddly undocumented) way to get the Authorization Code. Everything is working great! :D

0 Likes 0 ·
brendan avatar image brendan dan commented ·

Great, glad to hear it. For the sake of others that might run into this, which plugin is it, and what's the undocumented workaround to get the right auth code?

0 Likes 0 ·
dan avatar image dan brendan commented ·

It is Ultimate Mobile from Stan's Assets... but the same fix could work for Android Native, from the same publisher.

To get the Authorization Code use something like the following...

string authCode;
string webClientAppID = "long code copied from your Google Dev Console"; GooglePlayManager.ActionServerAuthCodeLoaded += ActionCodeLoaded; GooglePlayManager.Instance.GetGamesServerAuthCode(webClientAppID);

And then...

private void ActionCodeLoaded(GooglePlayResult result, string code)
{
Debug.Log("Got Code: " + code);
Debug.Log("Got Result Message: " + result.Message);
Debug.Log("Got Result Response: " + result.Response);
authCode = code;
}

Hope this helps! :)

0 Likes 0 ·
brendan avatar image
brendan answered

The scope is likely the issue - you need to specify the Profile scope for us to get the info we need to sign in. I'd recommend having a look at this tutorial: https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dan avatar image dan commented ·
Thanks for the info, Brendan!

I read through the documentation, and am now making sure that my oAuth token has the following scopes:

I still get the same error: Google API error code: invalid client details: unauthorized.

Not sure what I am still doing wrong. Any further suggestions I could investigate?

0 Likes 0 ·
fhg1507 avatar image fhg1507 commented ·

Dan sent to me an email, I'd like to talk to you Fernando@joysticket.com

I'm trying to use the same scope and getting the same error.

Cheers

0 Likes 0 ·
brendan avatar image brendan fhg1507 commented ·

Sorry, could you clarify this? Are you using the ServerAccessCode? Any plugins?

0 Likes 0 ·
fhg1507 avatar image
fhg1507 answered

Hi,

To use client id, client secret and return url´s, now you have to fill a form from google, saying why you´ll use this authentication.

I´ve been trying to use the same scope ( https://www.googleapis.com/auth/games )and now i got erros

Google has been changin oauth authentication.

https://security.googleblog.com/2017/05/protecting-you-against-phishing.html

Before may 11, everything works fine, but now, you have to fill this form to use any scope of google.

https://support.google.com/code/contact/oauth_app_verification

Now i don´t have any idea how my clients can fill this form to use the services provided from my website

Cheers

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Your players don't - the entity that needs to submit the new form to Google is the developer/publisher of the app in question which will use the OAuth system. So, you fill it out once, and then enter your OAuth Client ID and Secret to the Add-ons page for Google in the PlayFab Game Manager.

1 Like 1 ·
fhg1507 avatar image fhg1507 brendan commented ·

Brendan, for new clients from playfab, what are you recommending?Because i saw the form and i have no idea, how a developer can indicate that will use services from playfab or others companies who provide any service with oauth.

Cheers

0 Likes 0 ·
brendan avatar image brendan fhg1507 commented ·

If you look at the form, you'll notice that it requires the OAuth Client ID - that's unique per application running in Google. In other words, each game that wants to use their OAuth system for sign-in must complete the forum - as far as I can see, there's really no way around that. If you prefer not to, you don't have to use Google's authentication method. We have plenty of others (Facebook, Twitch, etc.) that you can use.

0 Likes 0 ·
dan avatar image
dan answered

Ahoy there! Was having a nightmare getting this to work on my second game, and stumbled across this note from my past self. I was having a different issue this time though: constant Google API error code: invalid_grant details: Bad Request errors.

Turns out these were caused by me resetting my password a few weeks ago and not re-authenticating Google Play Games on my test device. Only took me a day to work that out... :(

Check the article below for some handy pointers.

https://blog.timekit.io/google-oauth-invalid-grant-nightmare-and-how-to-fix-it-9f4efaf1da35

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.