Sign In Register

How can we help you today?

Start a new topic
Answered

Game Center / GS authentication

What is the recommend way to log in with Game Center?


My Game Center authentication is successful as the "welcome back" screen is showing.

Social.localUser.Authenticate(MyCallback)

But my call to GS is failing

	new GameCenterConnectRequest().Send((response) => {
		if (response.HasErrors){
			Debug.Log ("IOS login unsucessful");
		} else {
			Debug.Log ("IOS login sucessful");
			
			//things to do
			
		}
		
		Debug.Log("request done");
	});

 

The error message seem to mean that the display name and the externalPlayerId are required despite what the doc says.

I would gladly send forward those info, but I can't seem to get from where they could be retrieved.








Best Answer
A fix for this has been created and is available as an add-on package (due to possible problems with GameKit not being enabled during compile).

We will update the docs with this fix, but if it is not yet available you can request the unity-package by raising a ticket.

Thanks,
Sean

 


Hi Gabriel, 

Can you give me more information about the error? The usual method of doing this is by using response.Errors.JSON. this can be placed in your debug like so : Debug.Log ("IOS login unsucessful" + response.Errors.JSON); and will provide more info in console. As your error could be caused by a number of things this information will leave me better equipped to help you. 


Regards, Patrick. 

Yeah I wasn't clear. The content of the unsuccessful login error is "REQUIRED":"displayName". If i give a dummy display name. I instead get "REQUIRED":"externalPlayerId". 

I'm not sure from where I should get the externalPlayerId and the GameCenter default display name.

Or alternatively, if they were suppose to be automatically attributed, what could be the problem?

 i believe your request should look more like this, where the arguments inside .SetDisplayName and .SetExternalPlayerId are strings referenced from GameCentre Itself :

new GameSparks.Api.Requests.GameCenterConnectRequest().SetDisplayName().SetExternalPlayerId().SetPublicKeyUrl().
            .Send((response) => {
                if (!response.HasErrors)
                {
                    Debug.Log("Player Authenticated...");
                    userID = response.UserId;
                }
                else
                {
                    Debug.Log("Error Authenticating Player...");
                }
            });

 

 What version of the GameSparks sdk are you using might I ask? 

Regards Patrick. 

I have the 5.3.1.153 SDK for Unity.


And there is apparently no overload method accepting no parameter for SetDisplayName(), SetExternalPlayerId() and SetPublicKeyUrl() ...

I could have broken GUID in my iOS plugin folder from importing the Google Play Games Plugin... 

It could all be coming from this. I'll let you know.

The arguments for SetDisplayName(), SetExternalPlayerId() and SetPublicKeyUrl() are referenced externally from GameCentre. If those arguments are left empty then you are for all intents and purposes sending empty requests to GameSparks. 


Unless I am overlooking something that could well be your problem. If not we can work through it so please keep me updated.


Regards Patrick. 

I mis-understood your comment as if I needed to use empty strings for the GS SDK to fetch those info itself.


I think I got the playerId and displayName covered here:

socialDisplayName = Social.localUser.userName;
ios_externalPlayerId = Social.localUser.id;

Now the trouble is to get the strings from GameCenter. What is the proper way to do this?

How does one call generateIdentityVerificationSignatureWithCompletionHandler in C# ?


Hey Gabriel, 


you can use the following code to connect  GameSparks  to GameCentre. For it to work you have to already be connected to GameSparks. 

   

/// <summary>
    /// This method will connect gamesparks with gamecenter.
    /// If you are not connected with gamecenter it will first attempt to connect
    /// using the Unity Social api, and then re-attempt a gamesparks connection
    /// </summary>
    /// <param name="_displayName">_display name.</param>
    /// <param name="_callback">_callback.</param>
    public void GameCenterConnect(string _displayName, AuthenticateCallback _callback)
    {
        if(Social.localUser.authenticated)
        {
            Debug.Log("GS| Connecting With GameCenter...");
            GameSparksUtils.CreateGameGenterConnectRequest((request) =>{

                request.SetDisplayName(_displayName)
                    .Send((response)=> {
                        if(!response.HasErrors)
                        {
                            Debug.Log("GS| GameCenter Connected To GameSparks...");
                            _callback(response);
                        }
                        else
                        {
                            Debug.LogWarning("GS| Error Authenticating With GameCenter \n"+response.Errors.JSON.ToString());
                        }
                    });
            });
        }
        else
        {
            Debug.Log("GS| Must Connect With GameCenter First \n Attempting To Connect Using Unity Social...");
            Social.localUser.Authenticate((isConnected) => {
                if(isConnected)
                {
                    Debug.Log("GS| Connected With GameCenter...\n Will Attempt GameSparks Connection Again...");
                    GameCenterConnect(_displayName, _callback);
                }
                else
                {
                    Debug.LogWarning("GS| Error Connecting To GameCenter...");
                }
            });
        }
    }
    /// <summary>
    /// This method will connect gamesparks with gamecenter.
    /// If you are not connected with gamecenter it will first attempt to connect
    /// using the Unity Social api, and then re-attempt a gamesparks connection
    /// </summary>
    /// <param name="_displayName">_display name.</param>
    /// <param name="_callback">_callback.</param>
    public void GameCenterConnect(string _displayName)
    {
        if(Social.localUser.authenticated)
        {
            Debug.Log("GS| Connecting With GameCenter...");
            GameSparksUtils.CreateGameGenterConnectRequest((request) =>{
                
                request.SetDisplayName(_displayName)
                    .Send((response)=> {
                        if(!response.HasErrors)
                        {
                            Debug.Log("GS| GameCenter Connected To GameSparks...");
                            GameCenterConnect(_displayName);
                        }
                        else
                        {
                            Debug.LogWarning("GS| Error Authenticating With GameCenter \n"+response.Errors.JSON.ToString());
                        }
                    });
            });
        }
        else
        {
            Debug.Log("GS| Must Connect With GameCenter First \n Attempting To Connect Using Unity Social...");
            Social.localUser.Authenticate((isConnected) => {
                if(isConnected)
                {
                    Debug.Log("GS| Connected With GameCenter...\n Will Attempt GameSparks Connection Again...");
                }
                else
                {
                    Debug.LogWarning("GS| Error Connecting To GameCenter...");
                }
            });
        }
    }

   

hopefully this solves your problem and sorry for the confusion Gabriel. 

If you could get back to me and let me know if this was successful that would be great. 


Regards, Patrick. 

This is a very interesting bit of code. 

However, I apparently can't find the GameSparksUtils class or the CreateGameGenterConnectRequest method. Is this code for an earlier release of the SDK? Or I am still missing something?

I've still not found the GameSparksUtils class anywhere. Even in your web doc I cannot find anything about this class. I use the unity SDK, should I also install something from the obj-c sdk? 


Anyone else ever managed to make GS authenticate with Game Center? 


Everything works great with Android as I can fetch the required values from the google plugin:   

android_accessToken = PlayGamesPlatform.Instance.GetAccessToken();
socialDisplayName = PlayGamesPlatform.Instance.GetUserDisplayName ();
new GooglePlusConnectRequest ().SetAccessToken(android_accessToken).Send ((response) => {
...
});


Hi Gabriel, 

I'm going to raise this with our Tech Support team and see what's going on. It may be that the feature needs updating etc. 

I'll be back to you soon with an answer. Thanks for your patience. 

Regards, Patrick. 

Any clue on why I can't log iOS devices to GS? I'm pretty much at the same point.


I get values from :

socialDisplayName = Social.localUser.userName;
ios_externalPlayerId = Social.localUser.id;

But GameCenterConnectRequest() get an error :

{"REQUIRED":"salt"}

 And I have no idea from where to get this salt. 


Best,


Gabriel

Hey Gabriel,

Im very sorry for this; i advised Paddy on the solution he supplied you without checking the changeset had been passed to the SDK.
So this was a fix we have no yet implemented into the main SDK yet.
I can offer you a build with this fix implemented, however i cannot guarentee it will be 100% stable, as i have just made this fix  a feature request.

Again, i am very sorry for the confusion and for misssing this forum post.
Please let me know if you would like the sample-project also, as i do not yet have an eta for whern this fix will be added to the mian SDK.

Sean

 

Login to post a comment