Sign In Register

How can we help you today?

Start a new topic

Authenticating with google play tutorial (Unity3d)

since i was stuck on this issue for about a week here is the solution to how to authenticate with google play.


1.create new web app link in google play console

set LaunchURL to https://www.gamesparks.com/ and click ok


2.once configured go to your api console once there click edit on web application and change Authorized redirect URIs from https://www.gamesparks.com/oauth2callback to
http://www.gamesparks.com/oauth2callback


3.configure gamesparks integration

set google app id (this can be found in google play console)

set Google Application Client ID to your web app client id don't put your android client id or it will not work

set Google Application Client Secret to your web app client secret


4.open unity and navigate to google play games android configuration and in client id field paste your web app client id


5.initialize google play games

 PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            .RequestServerAuthCode(false)
            .Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();

        Social.localUser.Authenticate(success => { });

6.gamesparks authentication

 

note! redirect uri must be the same in your code and in your api console or you will get NOTAUTHENTICATED error

string displayName = PlayGamesPlatform.Instance.GetUserDisplayName();
        string AuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();

        new GooglePlayConnectRequest()
        .SetCode(AuthCode)
        .SetRedirectUri("http://www.gamesparks.com/oauth2callback")
        .SetDisplayName(displayName)
        .Send((googleplayAuthResponse) =>
        {
            if (!googleplayAuthResponse.HasErrors)
            {
                Debug.Log("GameSparks Authenticated!");
            }
            else
            {
                Debug.Log(googleplayAuthResponse.Errors.JSON);
            }
        }
        );

 

 

 


3 people have this question

Thanks for the info. Does this actually work for you? I just followed the same steps (but for Android not Unity) and I still get NOTAUTHENTICATED response. I feel like there is an issue in GameSparks call to google server asking to exchange ServerAuthCode for an AccessToken...


4 people like this

When I try this , i get google connection, but no auth through gamesparks. it pops up with accessToken":|required" or something along those lines, the error says it means there is no code, or token !? 

Worked for me thanks

Do you always use the .SetCode(AuthCode) in the GooglePlayConnectRequest call? First time I used this code, it gave me an AuthCode correctly, but now every time I login the AuthCode is empty.


The user was correctly associated though, as my ExternalAuthentications and externalIds fields are correctly filled.


I'm getting the Gamesparks Error "AccesToken REQUIRED" now.


image


The UserID matches the one that Googles send me with the one stored in Gamesparks Player table.


Should I handle the login differently depending if the user is already linked to google or not? Because right now I'm using the same code for both cases, and I don't even know how to differentiate both scenarios.


Any help or a code snippet from the Login Flow from someone who has thiw working would be much appreciated.

That worked for me after a huge suffering between google and Gamesparks documentations!


Thank you so much! 

Amera,

I am also stuck at this one, here the error message.

{"googleError":{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}},"code":"NOTAUTHENTICATED"}


I already checked the Ids and followed the steps, but still no luck. I have no clue what to try or what could be wrong. Any help is appreciated.

Login to post a comment