I want to get authorisation code to enable server-side API access for my app. I do this process in Unity3D with google play games services plugin for Unity. I have function that calls native getToken() function from GoogleAuthUtils class:
public string GetToken() {
string token = null;
Debug.Log("Before RetrieveUserEmail");
string email = RetrieveUserEmail() ?? "NULL";
Debug.Log("After RetrieveUserEmail email: " + email);
string scope = "oauth2:server:client_id:" + "666666666666-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com"
+ ":api_scope:" + "https://www.googleapis.com/auth/plus.login";
using (AndroidJavaClass jc_unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"),
jc_gau = new AndroidJavaClass("com.google.android.gms.auth.GoogleAuthUtil")) {
using(AndroidJavaObject jo_Activity = jc_unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
token = jc_gau.CallStatic<string>("getToken", jo_Activity, email, scope);
}
}
Debug.Log("Token " + token);
return token;
}
but I get AndroidJavaException: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
This function seams to be OK, as it works with
string scope = "audience:server:client_id:" + "666666666666-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com"
and returns audience token.
I don't imagine what am I doing wrong.
Any suggestions?
Or maybe You can clarify, that is using URL call:
redirects me to url like
that has in parameter code = 4/YUVer...
is that code the SAME one as that I am trying to get via Unity function?
Thank in advance, I will appreciate any help.