Sign In Register

How can we help you today?

Start a new topic
Answered

ScriptData on AuthenticationResponse is always null when using DeviceAuthenticationRequest

Hey there!


When using the DeviceAuthenticationRequest with Unity in the AuthenticationResponse, ScriptData is always null. Is this a a known issue or is the only workaround to make an additional AccountDetailsRequest after authentication?


Thanks a lot


Best Answer

Hi Julian, 


In the Cloud Code for either of those responses you could have scriptData set as follows.


Spark.setScriptData("test", "value")

 

Then in Unity you could use the following to retrieve it.


 

Debug.Log(response.ScriptData.GetGSData("scriptData").GetString("test"));

 

 

This will just print the value to the log but you can do whatever you want with it at this point. Try that and let us know how you get on.


Regards,

Liam


Answer

Hi Julian, 


In the Cloud Code for either of those responses you could have scriptData set as follows.


Spark.setScriptData("test", "value")

 

Then in Unity you could use the following to retrieve it.


 

Debug.Log(response.ScriptData.GetGSData("scriptData").GetString("test"));

 

 

This will just print the value to the log but you can do whatever you want with it at this point. Try that and let us know how you get on.


Regards,

Liam

Thanks for yourquick answer. 

So i have to add the scriptData (Spark.setScriptData("test", "value") to the AuthenticationResponse CloudCode Script to have it available in Unity after authentication? is that right?

Hello, Julian.


I am not 100% sure, but I had similar case with yours. And I think I have solved it.

My use case is following.


In Unity, I called DeviceAuthenticationRequest as following

 

new DeviceAuthenticationRequest()
                    .SetDisplayName(userName)
                    .SetSegments(new GSRequestData().AddString("SEG_PLAYERTYPE", SystemConfig.SEG_PLAYERTYPE))
                    .SetScriptData(new GSRequestData().AddString("AppVersion", SystemConfig.APP_VERSION))
                    .Send(response =>
                    {
                      // Some handling
                    });

 

Then, in Cloud Code's Request->AuthenticationRequest, I set scriptData as following,

 

// AuthenticationRequest
var fromClient = Spark.getData().scriptData;
if(fromClient["AppVersion"])
{
    Spark.setScriptData("AppVersion", fromClient["AppVersion"]);
}

 

Finally, I could received "AppVersion" from Cloud Code's AuthenticationResponse

 

var authenError = Spark.getData().error;

// If there is an error for authentication, do not process the daily reward
if(authenError == null)
{
    // Will return exact string value of "AppVersion"
    var testOne = Spark.getScriptData("AppVersion");
   // Will return Json object as formed of {"AppVersion":"1.0.0"}
    var testTwo = Spark.getData().scriptData;
}

 

Without using Spark.setScriptData at any Request, the scriptData passed from Client can't be delivered to corresponded Response.


Hope it helps you.


Danny



Also, note that, if you called DeviceAuthenticationRequest @ Unity, then you have to write 


Spark.setScriptData("AppVersion", fromClient["AppVersion"]);


to DeviceAuthenticationRequest @ Cloud Code's Request.

Hey there...that helped a lot. Tahnk you, now its working !!!

Login to post a comment