Hy guys,
We are having troubles getting the server auth code from Google: GetServerAuthCode() always returns null. The code below is a Coroutine that I run after Social.localUser.Authenticate() ( which is successful ). We are using the DefaultConfiguration for PlayGamesPlatform.Instance and the Android Setup is done correctly ( with the Web App Id ).
This worked before updating from 0.9.34 to 0.9.38.
Play Games Plugin version : 0.9.38
Unity: 5.6.0f3
We also tried adding PlayGamesPlatform.Instance.GetServerAuthCode() in the yield but it never returned true.
There must be something we migh overlooked, any help would be much appreciated.
```csharp
yield return new WaitUntil(() => {
return PlayGamesPlatform.Instance.IsAuthenticated();
});
GooglePlayGames.OurUtils.PlayGamesHelperObject.RunOnGameThread(() =>
{
var result = PlayGamesPlatform.Instance.GetServerAuthCode();
if (!string.IsNullOrEmpty(result)) {
AuthenticateSucces(PlayGamesPlatform.Instance.GetUserId(), result);
} else {
Debug.LogError("Can't get Google Play token");
}
});
The server auth code needs to be requested when building the PlayGames configuration. See https://github.com/playgameservices/play-games-plugin-for-unity#configuration--initialization-play-game-services for the example code.
You also have to configure the web app that is linked to the same game in the play console. Then copy the client id from the web app and paste it into the setup dialog for the plugin.
If you do both of those and it still does not work, please share a log of authenticating.
I have the same exact problem. But our works the second time i launch the app.
Trying to upgrade from 0.9.33 to 0.9.38.
why did you ditch the callback ? :(
edit: i tried some more and realized it doesn't returns null string but returns Empty string.
Hy,
Iâve set the following code:
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
to be called right before PlayGamesPlatform.Activate(); and still the auth code is empty.Also now the user will get a second window to allow permissions to manage game activity.
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Application is pausing, which disconnects the RTMP client. Leaving room.
V/GamesNativeSDK: Play Games callback indicates connection.
I/GamesNativeSDK: Successfully connected to Google Play.
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Starting Auth Transition. Op: SIGN_IN status: VALID
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Populating User
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Found User: [Player: 'æ
ç°ä¹æµ¡ã¥ç²
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Maybe finish for User
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Auth not finished. User=[Player: 'æ
ç°ä¹æµ¡ã¥ç²
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Entering internal callback for AchievementManager#InternalFetchAllCallback
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Populating Achievements, status = VALID
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Found 10 Achievements
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Maybe finish for Achievements
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Auth finished. Proceeding.
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Invoking Callbacks: System.Action`2[System.Boolean,System.String]
I/Unity: <color=grey>[»]</color> [GPGS] Social Authenticate
GameManager:<SocialAuthenticate>m__7D(Boolean, String) ()
GooglePlayGames.Native.<InvokeCallbackOnGameThread>c__AnonStorey1`2:<>m__0()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
I/Unity: <color=grey>[»]</color> [GPGS] Is Authenticated? True
<OnRequestAccesToken>c__Iterator50:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.MonoBehaviour:StartCoroutine_Auto_Internal(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
GameManager:<SocialAuthenticate>m__7D(Boolean, String)
I/Unity: [Play Games Plugin DLL] 05/10/17 16:01:55 +03:00 DEBUG: Invoking user callback on game thread
I/Unity: ---- [0] -- 2097185
Google.Developers.JavaObjWrapper:ConstructArgArray(Object[])
Google.Developers.JavaObjWrapper:InvokeCallVoid(String, String, Object[])
Com.Google.Android.Gms.Common.Api.PendingResult`1:setResultCallback(ResultCallback`1)
GooglePlayGames.Android.AndroidClient:GetPlayerStats(IntPtr, Action`2)
GooglePlayGames.
E/Unity: returning server auth code
GooglePlayGames.PlayGamesPlatform:GetServerAuthCode()
<OnRequestAccesToken>c__Iterator50:<>m__1()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
I/Unity: <color=grey>[»]</color> [GPGS] Code from Server:
<OnRequestAccesToken>c__Iterator50:<>m__1()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
E/Unity: Cant get Google Play token
<OnRequestAccesToken>c__Iterator50:<>m__1()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
We already have the Android setup with the correct web app ID.
There was a pretty bad bug in 0.9.38 dealing how strings were passed to the C++ library from C#. Does it still happen if you upgrade to 0.9.38a?
hi.
It still occurs at 0.9.38a.
PlayGamesPlatform.Instance.GetServerAuthCode() is empty string.
but, 0.9.36 work fine.
Same issue here,
GetServerAuthCode() returns null.
any news on this issue?
Hello, we also updated the plugin to 0.9.38a. but it still does not work. We had to go back to 0.9.34 and enable Google+ API for it to work.
Will this issue be fixed in the new version?
@claywilkinson any updates on this?
@claywilkinson would be really nice if this was fixed since the current alternative is to not use the plugin at all (rolling back isn't a great option)
I'm having the exact same problem:
On a fresh installation of my app, the id token returns empty. After closing the application and opening again, the id token returns normally. If I close the app and open it again a few hours later, the same thing happens.
Further debugging the code, it looks like the callback that is executed after the token is obtained (line 172 of AndroidTokenClient.cs) is executed after the HandleAuthTransition method in NativeClient.cs. I'm not sure how to work around this problem, as I'm not familiar with the plugin, but maybe this will help the devs figure out what's going on.'
EDIT:
I worked around the problem by being able to set a callback function when the idToken changed in the plugin. In order to do this, I've modified the AndroidTokenClient.cs class to invoke a callback that I can control from my code:
```c#
pr.setResultCallback(new TokenResultCallback((rc, authCode, email, idToken) =>
{
this.authCode = authCode;
this.email = email;
this.idToken = idToken;
onIdTokenChange(idToken); // <-- This function is passed through
callback();
}));
In my code, I do something like this:
```c#
public void Start()
{
config = new PlayGamesClientConfiguration.Builder()
.RequestIdToken()
.SetOnIdTokenChange(OnIdTokenChanged) // <-- This function is added by me
.Build();
}
So the SetOnIdTokenChange() receives a function (Action
There are a few classes that need to be modified (PlayGamesClientConfiguration, Builder, NativeClient, and TokenClient) in order to create the SetOnIdTokenChange function and passing the parameter it takes through.
In this way, even if the callback set in the PlayGamesPlatform.Instance.Authenticate() method is called before the token is recieved in the AndroidTokenClient class callback is called, I will still get the id token.
This is of course a ver Hacky way of doing this, but in my particular scenario it gets the job done.
At first I had the same problem but the problem was a bad setup. Im using 0.9.38a version.
My code:
` PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestIdToken()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
googleIdToken = ((PlayGamesLocalUser)Social.localUser).GetIdToken();
Credential credential =
GoogleAuthProvider.GetCredential(googleIdToken, null);`
Be sure to Authentication is enabled and set your Web App Client Id



Wow! This is a very active thread! (Thanks for all the contributions/advice!). Unfortunately, it seems like there are a couple different issues being discussed. To summarize:
Hello @claywilkinson I am still unable to see the value of the PlayGamesPlatform.Instance.GetAccessToken () or PlayGamesPlatform.Instance.GetServerAuthCode() they are always empty strings. Ive tried running them in the main thread with the PlayGamesHelperObject.RunOnGameThread and still nothing. (In 0.9.36 and now in 0.9.38a)
I read what @DanielParra159 said and went to the developer console and made sure that my OAuth2 client id was the same that in the game, and indeed it was. In the developer console the OAuth2 client ID is from and Android app I am not sure If I would need to add a "Web app" version to link it to the Android one in Unity? Also because the log mentions something a bit related to that. Even if that doesnt make much sense.

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken ().Build ();
PlayGamesPlatform.InitializeInstance (config);
PlayGamesPlatform.Activate ();
Debug.Log ("IdToken: "+((PlayGamesLocalUser)Social.localUser).GetIdToken ());
OUTPUT
idToken:
Below is the log, at the end there is a debug log like the following and still is an empty string:
Debug.Log ("C91DEBUG: localUserIdToken: " + (((PlayGamesLocalUser)Social.localUser).GetIdToken ()));
Debug.Log ("C91DEBUG: IdToken: "+PlayGamesPlatform.Instance.GetIdToken ());
E/TokenFragment( 651): Already a pending token request!
D/TokenFragment( 651): Fragment exists.. calling processRequests
D/TokenFragment( 651): Done with processRequest!
W/GamesServiceBroker( 2016): Client connected with SDK 10298000, Services 10298236, and Games 39080036
I/Unity ( 651): ---- [0] -- 2097221
I/Unity ( 651): UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
I/Unity ( 651): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
I/Unity ( 651): UnityEngine.Logger:Log(LogType, Object)
I/Unity ( 651): UnityEngine.Debug:Log(Object)
I/Unity ( 651): Google.Developers.JavaObjWrapper:ConstructArgArray(Object[]) (at GooglePlayGames\Platforms\Android\Developers\JavaObjWrapper.cs:156)
I/Unity ( 651): Google.Developers.JavaObjWrapper:InvokeCallVoid(String, String, Object[]) (at GooglePlayGames\Platforms\Android\Developers\JavaObjWrapper.cs:284)
I/Unity ( 651): Com.Google.Android.Gms.Common.Api.PendingResult`1:setResultCallback(ResultCallback`1) (at GooglePlayGames\Platforms\Android\Gms\Common\Api\PendingResult.cs:55)
I/Unity ( 651): GooglePlayGames.Android.AndroidTokenClient:DoFetchToken(Action) (at C:\Unity 5.6.0f3\Project\
W/GamesServiceBroker( 2016): Client connected with SDK 8487000, Services 10298236, and Games 39080036
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/GamesServiceBroker( 2016): Client connected with SDK 8487000, Services 10298236, and Games 39080036
W/Auth ( 2290): [GetToken] GetToken failed with status code: INVALID_AUDIENCE
E/TokenRequestor( 2016): You have wrong OAuth2 related configurations, please check. Detailed error: INVALID_AUDIENCE
E/TokenFragment( 651): Error with silentSignIn: Status{statusCode=DEVELOPER_ERROR, resolution=null}
D/TokenPendingResult( 651): Calling onResult for callback: GooglePlayGames.Android.TokenResultCallback result: Status: Status{statusCode=DEVELOPER_ERROR, resolution=null} email: <null> id:<null> access: <null>
D/Unity ( 651): Unloading 2 Unused Serialized files (Serialized files now loaded: 0)
D/Unity ( 651): IPv6 on!
D/Unity ( 651):
I/Unity ( 651): C91DEBUG: localUserIdToken:
@VicEsquivel - The web app client id is needed to get the id token and auth code. If you need these fields you must create a web client app and associate it with your game. Use the client id of the web app in the __Web App Client Id__ field in setup.
@claywilkinson This worked. Thanks!.
But only for the IdToken, the GetServerAuthCode is still empty.
Strange..Can you share the log of the idToken working and the authCode not?
There was a race condition between the C++ library silently signing in and the explicit java signin. This is fixed in 0.9.39a.
@claywilkinson
Ive been back and forth in new versions[0.9.39 and now this one 0.9.39a] but version 0.9.36 is the one I think has most of what I need to work good. Except for one anoying pop up that appears everytime I login silently. The pop up is to pick an email. Also I think I saw once that 0.9.36 was not working correctly on some devices, but until now is my best shot. I mean the GetAccessToken() works good on that one.
I upgraded to 0.9.39a and with this code I am still back to square one. I am unable to get neither the code or the getIdToken.
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken ().RequestServerAuthCode (true).Build ();
PlayGamesPlatform.InitializeInstance (config);
PlayGamesPlatform.Activate ();
This is the log of version 0.9.39a:
(Related to this last version 0.9.39a it has in the log my Web App Client Id, I think that is pretty unsecure right? or is this just a debugging version?)
I/Unity (22892): GooglePlayGames.Native.NativeClient:Authenticate(Action`2, Boolean) (at \Assets\GooglePlayGames\Platforms\Native\NativeClient.cs:129)
I/Unity (22892): GooglePlayGames.PlayGamesPlatform:Authenticate(Action`2, Boolean) (at \Assets\GooglePlayGames\ISocialPlatform\PlayGamesPlatform.cs:426)
I/Unity (22892): GooglePlayGames.PlayGamesPlatform:Authenticate(Action`1, Boolean) (at \Assets\GooglePlayGames\ISocialPlatform\PlayGamesPlatform.cs:395)
I/Unity (22892): GooglePlayGames.PlayGamesPlatform:Authenticate(Action`1) (at \Assets\GooglePlayGames\ISocialPlatform\PlayGa
D/Unity (22892): Unloading 0 Unused Serialized files (Serialized files now loaded: 0)
W/Unity (22892): (Filename: C Line: 0)
W/Unity (22892):
W/Unity (22892): !!! [Play Games Plugin DLL] 06/07/17 20:44:33 -05:00 WARNING: Creating new PlayGamesPlatform
W/Unity (22892): UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
W/Unity (22892): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
W/Unity (22892): UnityEngine.Logger:Log(LogType, Object)
W/Unity (22892): UnityEngine.Debug:LogWarning(Object)
W/Unity (22892): GooglePlayGames.OurUtils.<w>c__AnonStorey1:<>m__0() (at \Assets\GooglePlayGames\OurUtils\Logger.cs:68)
W/Unity (22892): GooglePlayGames.OurUtils.PlayGamesHelperObject:Update() (at \Assets\GooglePlayGames\OurUtils\PlayGamesHelperObject.cs:135)
W/Unity (22892):
W/Unity (22892): (Filename: C Line: 0)
W/Unity (22892):
D/TokenFragment(22892): Creating fragment
D/Unity (22892): IPv6 on!
D/Unity (22892):
D/TokenFragment(22892): onStart()
D/TokenFragment(22892): onResume called
D/TokenFragment(22892): Building client for: 1ebb6509 (a:true e:false i:true wc: [HERE WAS MY WEB CLIENT ID] f: true)
I/Unity (22892): ---- [0] -- 33
I/Unity (22892): UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
I/Unity (22892): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
I/Unity (22892): UnityEngine.Logger:Log(LogType, Object)
I/Unity (22892): UnityEngine.Debug:Log(Object)
I/Unity (22892): Google.Developers.JavaObjWrapper:ConstructArgArray(Object[]) (at \Assets\GooglePlayGames\Platforms\Android\Developers\JavaObjWrapper.cs:156)
I/Unity (22892): Google.Developers.JavaObjWrapper:InvokeCallVoid(String, String, Object[]) (at \Assets\GooglePlayGames\Platforms\Android\Developers\JavaObjWrapper.cs:284)
I/Unity (22892): Com.Google.Android.Gms.Common.Api.PendingResult`1:setResultCallback(ResultCallback`1) (at \Assets\GooglePlayGames\Platforms\Android\Gms\Common\Api\PendingResult.cs:55)
I/Unity (22892): GooglePlayGames.Android.AndroidTokenClient:DoFetchToken(Action`1) (at
D/TokenFragment(22892): No connected Games API,!!!! Hoping for connection!
D/TokenFragment(22892): Done with processRequest!
W/GamesServiceBroker( 2016): Client connected with SDK 10298000, Services 10298236, and Games 39080036
W/GamesServiceBroker( 2016): Client connected with SDK 8487000, Services 10298236, and Games 39080036
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/GamesServiceBroker( 2016): Client connected with SDK 8487000, Services 10298236, and Games 39080036
W/Auth ( 2290): [GetToken] GetToken failed with status code: NeedPermission
W/Auth ( 2016): [GoogleAuthUtil] GoogleAuthUtil
E/TokenFragment(22892): Error with silentSignIn: Status{statusCode=SIGN_IN_REQUIRED, resolution=null}
D/TokenPendingResult(22892): Calling onResult for callback: GooglePlayGames.Android.TokenResultCallback result: Status: Status{statusCode=SIGN_IN_REQUIRED, resolution=null} email: <null> id:<null> access: <null>
D/GamesUnitySDK(22892): Performing Android initialization of the GPG SDK
I/Unity (22892): Building GPG services, implicitly attempts silent auth
I/Unity (22892): UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
I/Unity (22892): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
I/Unity (22892): UnityEngine.Logger:Log(LogType, Object)
I/Unity (22892): UnityEngine.Debug:Log(Object)
I/Unity (22892): GooglePlayGames.Native.NativeClient:InitializeGameServices() (at \Assets\GooglePlayGames\Platforms\Native\NativeClient.cs:224)
I/Unity (22892): GooglePlayGames.Native.NativeClient:<Authenticate>m__0(Int32) (at \Assets\GooglePlayGames\Platforms\Native\NativeClient.cs:132)
I/Unity (22892): GooglePlayGames.Android.<DoFetchToken>c__AnonStorey1:<>m__0(Int32, String, String, String) (at \Assets\GooglePlayGames\Platforms\Android\AndroidTokenClient.cs:172)
I/Unity (22892): GooglePlayGames.Android.TokenResultCallback:OnResult(TokenResult) (at A
I/GamesNativeSDK(22892): Using existing jar.
I/GamesNativeSDK(22892): Writing 1941 bytes to jar file
I/GamesNativeSDK(22892): Using existing jar.
I/GamesNativeSDK(22892): Writing 1066 bytes to jar file
I/GamesNativeSDK(22892): Auth operation started: SIGN IN
I/GamesNativeSDK(22892): Connecting to Google Play...
W/GamesServiceBroker( 2016): Client connected with SDK 10298000, Services 10298236, and Games 39080036
W/GamesServiceBroker( 2016): Client connected with SDK 8487000, Services 10298236, and Games 39080036
W/SQLiteConnectionPool( 2016): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
W/SQLiteConnectionPool( 2016): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
W/SQLiteConnectionPool( 2016): A SQLiteConnection object for database '/data/data/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/GamesServiceBroker( 2016): Client connected with SDK 8487000, Services 10298236, and Games 39080036
D/Unity (22892): IPv6 on!
D/Unity (22892):
V/GamesNativeSDK(22892): Play Games callback indicates connection.
I/GamesNativeSDK(22892): Successfully connected to Google Play.
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
W/AppOps ( 870): Bad call: specified package com.google.android.play.games under uid 10320 but it is really 10110
@claywilkinson
I ran the whole thing again with the boolean inside the request for the code set to false and it worked good. I can see both.
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken ().RequestServerAuthCode (false).Build ();
PlayGamesPlatform.InitializeInstance (config);
PlayGamesPlatform.Activate ();
EDIT: Now it is working!!. It was my fault. I have my google code wrapped with this compilation tag #if UNITY_ANDROID && !UNITY_EDITOR. Supposedly, it should work well on the device, but it seems the device didn't like it.
Hi everybody,
@VicEsquivel, I am using also de last version ( 0.3.9a). I am able to authenticate, but unfortunately, I am not able to get neither the auth code nor the token Id.
My only doubt is in the config of the Google developer console, Web application menu, where I have to set the restrictions to authorize Javascript and the redirect URI. Even though the requests are not done from a web browser, this is the only place where I think I may have something wrong.
What values did you use here?.
I am using this:
Authorized JavaScript origins : http://www.gamesparks.com
Authorized redirect URIs: http://www.gamesparks.com/oauth2callback
Thanks in advance
If you try to read the auth code or the token Id as soon as you authenticate successfully, I get in both cases an empty value. However, if you wait for 0.5f before reading the values, it works as expected.
I am using a:
yield return new WaitForSeconds (0.5f);
before reading the AuthCode, and works well
Interesting @MomoVideogames - can you share a code snippet of where you put that? Maybe there is weird threading side effect going on.
So is it ok to close this thread out @VicEsquivel ?
@claywilkinson I think yes, everything seems to be working fine.
GetServerAuthCode seems to depend on setting both RequestServerAuthCode(false) and RequestIdToken() in PlayGamesClientConfiguration. Is this intended behavior on 0.9.39a?
On initial run when user is prompted for the required permissions everythingâs working. After restarting the app, on subsequent authentications I seem to be always getting a null auth code if either omitting RequestIdToken() or setting the force refresh flag to true. Log then shows a âGetToken failed with status code: NeedPermissionâ error.
Attached is a log of the case without RequestIdToken set.
logcat_idtoken_off_refresh_flag_off_2_output.txt
I ran into the same problem. And I resolved this problem by clicking the Setup button in the plugin's setup window again.
In my case, I upgraded the plugin by overwriting the existing plugin directory. So, GameInfo.cs was overwritten, too. As you know, when you click the Setup button, the plugin generates GameInfo.cs file which has the web client ID you've written in the setup dialog.
Please check if the web client ID in GameInfo.cs is valid.
Its happening on 0.9.42 as well. I dont get any errors or warnings on the logcat its just empty every time. Token id also returns empty.
This also happens on 0.9.50 with Unity 2017.2.1p1.
I've been through every thread on github, stackoverflow, etc, and my app gets authenticated, but the server auth code is empty. Multiple runs give the same result - empty server auth code. I even tried adding a delay, as someone recommended, but none of the resolutions fixed it.
I also get a "manage game activity" permission popup on every run, in addition to seeing the normal toasts that tell me my Google Play login worked. And my debug output confirms that I am authenticated.
This is a complete brick wall now. :(
Update: I downgraded to 0.9.42 and it worked ONCE. But every time after that, the server auth code is empty. And I'm still getting the permission popup for "manage game activity" on every single login. That doesn't seem normal.
Update2: Adding .RequestTokenId() to the GPGS init config actually resolved it. The server auth code comes through, if this call exists. But that seems like a bug, because I don't actually need a token id (I only need the server auth code), and why does getting an auth code require also getting a token??
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:26 -08:00 DEBUG: Activating PlayGamesPlatform.
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:26 -08:00 DEBUG: PlayGamesPlatform activated: GooglePlayGames.PlayGamesPlatform
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:26 -08:00 DEBUG: Creating platform-specific Play Games client.
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:26 -08:00 DEBUG: Creating Android IPlayGamesClient Client
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Starting Auth Transition. Op: SIGN_IN status: 4
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Invoking callbacks, AuthState changed from silentPending to Unauthenticated.
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: there are pending auth callbacks - starting AuthUI
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Starting Auth Transition. Op: SIGN_IN status: VALID
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Entering internal callback for PlayerManager#InternalFetchSelfCallback
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Populating User
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Found User: [Player: 'omgJasonDev1' (id g14733868697792692841)]
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Maybe finish for User
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Auth not finished. User=[Player: 'omgJasonDev1' (id g14733868697792692841)] achievements=
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Entering internal callback for AchievementManager#InternalFetchAllCallback
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Populating Achievements, status = VALID
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Found 0 Achievements
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Maybe finish for Achievements
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Auth finished. Proceeding.
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Invoking Callbacks: System.Action`2[System.Boolean,System.String]
<i>AndroidPlayer(samsung_SAMSUNG-SM-G900A)</i> [Play Games Plugin DLL] 02/05/18 8:53:39 -08:00 DEBUG: Invoking user callback on game thread
I have the same problem.
tried all.
help please.
this is awfull.
no auth code,
no id token.
no email.
only username and google id.
help.
Update:
Fixed it, i was calling PlayGamesPlatform.Activate() in another method before the one that whas suposed to do it, so it had no cofig.
Unity 5.6.0f3
GPGS 0.9.39
i fixed this by upgrading to 39a
I am now having the same problem with 0.9.41, when previously GetServerAuthCode() would return an access code every time. This code seemed to stop working all together, so perhaps there is a race condition here? I am seeing that sometimes, you can get an access code and then after a certain number of times (mostly just once) a GPG account gets stuck and will never return a code again in that device. Here is what I have tried from reading the thread;
RequestTokenId() to the config as per @jason-otherwhere 's suggestion.PlayGamesPlatform.Activate() is only called at least once.Play Games Plugin DLL output looks the same as Jason's above; indicates no problems. Authenitcation is fine, I just get an empty string from GetServerAuthCode or GetAnotherServerAuthCode.
@claywilkinson I would very much appreciate some help here. Are there any dependencies that would cause this problem? Would there be any logs to look out for/add to indicate where the problem is? (I could try building the plugin myself with extra logs).
This is how I fixed this issue:
Make sure all of the things mentioned by @JimmyDeemo are fine.
If authentication works fine but there is still no authCode, try to signout PlayGamesPlatform.Instance.SignOut() and signIn again and check if you get the Auth code.
Also I would recommend that you save the authCode the first time you get a non empty value and continue using the saved value incase it's null in future logins. (Don;t forget to keep the saved code updated to the latest non null value)
Hope it helps!
The problem with the above approach is as follows;
My code, as it stands, is now working again. Give me an access code everytime for an account that didn't work before. Please can someone tell me if there is any network communication going on with getting the auth code?
I've been having the same problem consistently for the last 6 months of development and it has seriously slowed down the project.
The code returns a server authentication code most of the time but on the occassions it doesn't it breaks the game and is many attempts /uninstalls reinstall until it returns a code again.
At time of writing I can get a server code for the install on my phone but it will not return a code for the install on my tablet. As both installs are identical (both downloads from latest google play build) I can only assume this must be a problem on the server side.
My biggest worry is that this tends to happen after a new installation. Unless it can be fixed it's a project breaker.
If anyone has a solution different to the steps mentioned above it would be appreciated as they don't resolve the problem long term.
@claywilkinson have you reproduced this error yourselves? Is there anything happening server side that would cause this?
I finally managed to solve this problem. To do it:
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.RequestIdToken()
.Build();
PlayGamesPlatform.Instance.GetServerAuthCode();I have found a solution for me, which is to make sure you are not activating the platform close to when you are trying to authenticate/get the token.
I had a system that would try to self initialise i.e. setup the platform if it wasn't done before, authenticate the user if they are not. However this routinely caused me to not get a server auth code, and once it was stuck in this situation then it never recovered (perhaps null ref deep in the system?).
Here is what to try;
In first scene of your project, inside a MonoBehaviour under Start initialise the platform e.g.;
c#
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
Do not perform any other interactions with the platform at Start-time. Using this method I was able to get an auth code everytime. Hope it helps.
Edit: Also ensure you only activate the platform once per game launch.
Cant get this to work. I tried everything for a week now.
Signin in, out, waiting, all kinds of other idea.
But the server auth code is always empty. Does not matter whether I sign in for first time or later.
Any help appreciated.
Using plugin .50
I spent a lot of time, but I did not get the auth code, after that, I made my own plugin which immediately returned the code, I strongly advise not to waste time and make your plugin
I had my Google auth linking with Firebase perfectly until about a month ago, and then it just stopped working. Empty auth string coming back from the GPGS plugin every time. The Google account actually logs in -- I can get info from the Google account (player id, name, etc), but no auth string and therefore no link to Firebase. I've been trying every trick mentioned above, and quadruple checking my API settings, client ID settings, everything. It was so easy to get this working the first time, now I've spent over a month banging my head against the wall between other tasks. I've put a break point in the actual function inside the play games plugin and can see that it's an empty string coming back before it's ever passed to my code. Does anyone have any other ideas for what is going on here? Did something get changed on Google's end about a month ago? Or does someone know of another plugin solution available?
Hi All,
I had also been plagued by this problem for the past 2 weeks, and finally this week I decided to dig deeper into the code of the plugin (this plugin is great, but like any software not everything is perfect 100% of the time).
It turns out there is an async logical bug. If your plugin and logic to get the ServerAuthCode was working before and suddenly stopped working, or if you have everything configure and still getting a serverauthcode that is null, it is most likely due to how the plugin (or more specifically when the plugin) attempts to retrieve the serverauthcode.
The root of the problem starts from when you call:
Social.localUser.Authenticate or PlayGamesPlatform.Authenticate.
If it is called in the same code block as PlayGamesPlatform.Activate(); (in our case we had both calls in the Start() one after the other),
it is very likely that the PlayGamesPlatform hasn't finished initializing when PlayGamesPlatform.Authenticate is called.
The code as it is currently designed assumes a sequential flow of operation, but due to the async nature and network uncertainty of online calls, everything should be in chained callback.
To truly resolve the problem I had to expose AndroidTokenClient.FetchTokens all the way to PlayGamesPlatform (the result being a method PlayGamesPlatform.FetchTokens(Action
Basically some people were doing time hacks (like trying to delay the time between Activate and Authenticate, but due to network uncertinities the properly solution is a call back from fetch token).
I will do a pull request for PlaygamesPlatform.cs, NativeClient.cs and IPlayGamesClient.cs to help those that are having this issue. (Also to the core developers the method NativeClient.Authenticate(Action
For those that a wondering how I fixed it (while the pull request is pending)
In your Login Code you should have something like this:
var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
if (string.IsNullOrEmpty(serverAuthCode))
{
Logging.Live?.Log("{0}.HandleDelayedServerAuthTimerElapsed - User log. Userid = [{1}], Displayname = [{2}], IdToken[[{3}]",
GetType().Name,
PlayGamesPlatform.Instance.GetUserId(),
PlayGamesPlatform.Instance.GetUserDisplayName(),
PlayGamesPlatform.Instance.GetIdToken());
Logging.Live?.LogWarning("{0}.HandleDelayedServerAuthTimerElapsed - Server AuthCode is null or empty: [{1}]. We will attempt to manually fetch tokens.", GetType().Name, serverAuthCode);
PlayGamesPlatform.Instance.FetchTokens(FetchTokensCallback);
return;
}
Then you have to modify PlayGamesPlatform.cs to expose FetchTokens
/// <summary>
/// Asynchronously retrieves the tokens (email, idtoken and server auth code) from server
/// </summary>
/// <remarks>
/// This is a server call, and the result should be handled in the call back.
/// </remarks>
public void FetchTokens(Action<int> _callback)
{
if (mClient == null || !mClient.IsAuthenticated())
{
return;
}
mClient.FetchTokens(_callback);
}
Modify the interface IPlayGamesClient.cs
/// <summary>
/// Asynchronously retrieves the tokens (email, idtoken and server auth code) from server
/// </summary>
/// <remarks>
/// Note: This function is currently only implemented for Android.
/// </remarks>
void FetchTokens(Action<int> callback);
And finally NativeClient.cs
/// <summary>
/// Asynchronously retrieves the tokens (email, idtoken and server auth code) from server
/// </summary>
/// <remarks>Note: This function is currently only implemented for Android.</remarks>
/// <param name="serverClientId">The Client ID.</param>
/// <param name="callback">Callback for response.</param>
public void FetchTokens(Action<int> _callback)
{
if (!this.IsAuthenticated())
{
Debug.Log("Cannot get API client - not authenticated");
return;
}
mTokenClient.FetchTokens(_callback);
}
Summary:
Check to see if you were lucky to get a serverauthcode when you did Authenticate (I think the reason why lately it has been problematic for many people might be that the google servers aren't as responsive, and the induce lag is causing the issue), if serverauthcode is null, then fetch them again by calling PlayGamesPlatform.Instance.FetchTokens(FetchTokensCallback);
Hope this helps
Should be fixed in v0.9.54
Hi All,
I had also been plagued by this problem for the past 2 weeks, and finally this week I decided to dig deeper into the code of the plugin (this plugin is great, but like any software not everything is perfect 100% of the time).
It turns out there is an async logical bug. If your plugin and logic to get the ServerAuthCode was working before and suddenly stopped working, or if you have everything configure and still getting a serverauthcode that is null, it is most likely due to how the plugin (or more specifically when the plugin) attempts to retrieve the serverauthcode.The root of the problem starts from when you call:
Social.localUser.Authenticate or PlayGamesPlatform.Authenticate.If it is called in the same code block as PlayGamesPlatform.Activate(); (in our case we had both calls in the Start() one after the other),
it is very likely that the PlayGamesPlatform hasn't finished initializing when PlayGamesPlatform.Authenticate is called.
The code as it is currently designed assumes a sequential flow of operation, but due to the async nature and network uncertainty of online calls, everything should be in chained callback.To truly resolve the problem I had to expose AndroidTokenClient.FetchTokens all the way to PlayGamesPlatform (the result being a method PlayGamesPlatform.FetchTokens(Action _callback).
Basically some people were doing time hacks (like trying to delay the time between Activate and Authenticate, but due to network uncertinities the properly solution is a call back from fetch token).
I will do a pull request for PlaygamesPlatform.cs, NativeClient.cs and IPlayGamesClient.cs to help those that are having this issue. (Also to the core developers the method NativeClient.Authenticate(Action
callback, bool silent), especially the section if (mTokenClient.NeedsToRun()), needs to be redesigned to take into account that async nature of the call FetchTokens). For those that a wondering how I fixed it (while the pull request is pending)
In your Login Code you should have something like this:
var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode(); if (string.IsNullOrEmpty(serverAuthCode)) { Logging.Live?.Log("{0}.HandleDelayedServerAuthTimerElapsed - User log. Userid = [{1}], Displayname = [{2}], IdToken[[{3}]", GetType().Name, PlayGamesPlatform.Instance.GetUserId(), PlayGamesPlatform.Instance.GetUserDisplayName(), PlayGamesPlatform.Instance.GetIdToken()); Logging.Live?.LogWarning("{0}.HandleDelayedServerAuthTimerElapsed - Server AuthCode is null or empty: [{1}]. We will attempt to manually fetch tokens.", GetType().Name, serverAuthCode); PlayGamesPlatform.Instance.FetchTokens(FetchTokensCallback); return; }Then you have to modify PlayGamesPlatform.cs to expose FetchTokens
/// <summary> /// Asynchronously retrieves the tokens (email, idtoken and server auth code) from server /// </summary> /// <remarks> /// This is a server call, and the result should be handled in the call back. /// </remarks> public void FetchTokens(Action<int> _callback) { if (mClient == null || !mClient.IsAuthenticated()) { return; } mClient.FetchTokens(_callback); }Modify the interface IPlayGamesClient.cs
/// <summary> /// Asynchronously retrieves the tokens (email, idtoken and server auth code) from server /// </summary> /// <remarks> /// Note: This function is currently only implemented for Android. /// </remarks> void FetchTokens(Action<int> callback);And finally NativeClient.cs
/// <summary> /// Asynchronously retrieves the tokens (email, idtoken and server auth code) from server /// </summary> /// <remarks>Note: This function is currently only implemented for Android.</remarks> /// <param name="serverClientId">The Client ID.</param> /// <param name="callback">Callback for response.</param> public void FetchTokens(Action<int> _callback) { if (!this.IsAuthenticated()) { Debug.Log("Cannot get API client - not authenticated"); return; } mTokenClient.FetchTokens(_callback); }Summary:
Check to see if you were lucky to get a serverauthcode when you did Authenticate (I think the reason why lately it has been problematic for many people might be that the google servers aren't as responsive, and the induce lag is causing the issue), if serverauthcode is null, then fetch them again by calling PlayGamesPlatform.Instance.FetchTokens(FetchTokensCallback);Hope this helps
Sorry, but I tried out what you suggested with the current build "GooglePlayGamesPlugin-0.10.01" but I am getting this error: "error CS0535: 'DummyClient' does not implement interface member 'IPlayGamesClient.FetchTokens(Action
error CS0535: 'DummyClient' does not implement interface member 'IPlayGamesClient.FetchTokens(Action)
This error shows that you get a DummyClient instead of an AndroidClient because your game is being run from the Unity Editor. Check out this line.
Also, this issue is fixed, so you shouldn't need to use a workaround. You can try your game on an Android device and then share the logs if you face with problems again.
error CS0535: 'DummyClient' does not implement interface member 'IPlayGamesClient.FetchTokens(Action)
This error shows that you get a DummyClient instead of an AndroidClient because your game is being run from the Unity Editor. Check out this line.
Thank you for your reply, I already know that I am receiving this error because of the dummy client, I just wanna know if there is a way to get rid of this error? I already have this line in my PlayGamesClientFactory script but I still have the same error.
Also, this issue is fixed, so you shouldn't need to use a workaround. You can try your game on an Android device and then share the logs if you face with problems again.
Unfortunately, I still am having problems with the new google play service build. Nothing happens and I get this warning message when I attempt to log in. Do you have any ideas as to why?
Still having issues with this, we're on Unity 2019.2.18, 10.6 GPGS - it was working on one bundle id, webclient etc, we switched to another during a build and cannot get it to work at all - we've made sure all the setup is updated, GameInfo is correct, manifests and so on...looking into it further but just a heads up...
Hi Guys
I have an issue, but it is not the same as what you have something new.
I have testers in my Google Services, my SHA was changed correctly, yesterday I managed to do login with 2 different accounts and also to create 2 players in PlayFab. But when I unlinked one of the google accounts in PlayFab I couldn't log in back to google play game, I cannot obtain Auth Code anymore, fail to login, but I can obtain Auth Code for a second google account and successfully log in. How Does it work then? Is it a bug?
Attaching the logs, but not sure what error we are facing here.
Thank you In advance

Adding my Awake function.

Adding my login code

Which version of the plugin do you use? It seems as a possible issue fixed in 0.10.8
Hi @olehkuznetsov
Yes, I am using the latest version of the plugin, 0.10.8. I just don't understand why it was working but not anymore, I haven't change anything, it does working for one account but doesn't work for another, it doesn't make any sense.
Thanks
Can you create a new issue and attach a logcat as well, please?
Most helpful comment
Hi All,
I had also been plagued by this problem for the past 2 weeks, and finally this week I decided to dig deeper into the code of the plugin (this plugin is great, but like any software not everything is perfect 100% of the time).
It turns out there is an async logical bug. If your plugin and logic to get the ServerAuthCode was working before and suddenly stopped working, or if you have everything configure and still getting a serverauthcode that is null, it is most likely due to how the plugin (or more specifically when the plugin) attempts to retrieve the serverauthcode.
The root of the problem starts from when you call:
Social.localUser.Authenticate or PlayGamesPlatform.Authenticate.
If it is called in the same code block as PlayGamesPlatform.Activate(); (in our case we had both calls in the Start() one after the other),
it is very likely that the PlayGamesPlatform hasn't finished initializing when PlayGamesPlatform.Authenticate is called.
The code as it is currently designed assumes a sequential flow of operation, but due to the async nature and network uncertainty of online calls, everything should be in chained callback.
To truly resolve the problem I had to expose AndroidTokenClient.FetchTokens all the way to PlayGamesPlatform (the result being a method PlayGamesPlatform.FetchTokens(Action _callback).
Basically some people were doing time hacks (like trying to delay the time between Activate and Authenticate, but due to network uncertinities the properly solution is a call back from fetch token).
I will do a pull request for PlaygamesPlatform.cs, NativeClient.cs and IPlayGamesClient.cs to help those that are having this issue. (Also to the core developers the method NativeClient.Authenticate(Action callback, bool silent), especially the section if (mTokenClient.NeedsToRun()), needs to be redesigned to take into account that async nature of the call FetchTokens).
For those that a wondering how I fixed it (while the pull request is pending)
In your Login Code you should have something like this:
Then you have to modify PlayGamesPlatform.cs to expose FetchTokens
Modify the interface IPlayGamesClient.cs
And finally NativeClient.cs
Summary:
Check to see if you were lucky to get a serverauthcode when you did Authenticate (I think the reason why lately it has been problematic for many people might be that the google servers aren't as responsive, and the induce lag is causing the issue), if serverauthcode is null, then fetch them again by calling PlayGamesPlatform.Instance.FetchTokens(FetchTokensCallback);
Hope this helps