Skip to content

Instantly share code, notes, and snippets.

@agramonte
Created June 30, 2017 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agramonte/3c01f7d74cc38870c89269ee0bd15280 to your computer and use it in GitHub Desktop.
Save agramonte/3c01f7d74cc38870c89269ee0bd15280 to your computer and use it in GitHub Desktop.
//URL
/*
https://preview.gamesparks.net/callback/<gameAPIKey>/postScore/<credentialSecret>?
score=<playerScore> -- Needs to always be called score but it could represent anything. Whatever is being counted by the event.
&password=<playerPassword>
&username=<playerUsername>
&eventname=<leaderboardEventName> -- The name of the event that is attached to the leaderboard.
*/
var score = Spark.getData().score;
var uPwd = Spark.getData().password;
var uName = Spark.getData().username;
var eventname = Spark.getData().eventname;
var authenticationResponse = Spark.sendRequest(
{
"@class": ".AuthenticationRequest",
"password": uPwd,
"userName": uName
}
);
if (authenticationResponse.error == null) {
var logEventRequest = new SparkRequests.LogEventRequest();
logEventRequest.eventKey = eventname;
logEventRequest.score = score;
var logEventResponse = logEventRequest.ExecuteAs(authenticationResponse.userId);
if (logEventResponse.error == null) {
Spark.setScriptData("RESPONSE_RAW", '{"Status":"Success"}');
} else {
Spark.getLog().error(logEventResponse)
Spark.setScriptData("RESPONSE_RAW", '{"Status": ""}');
}
} else {
Spark.getLog().error(authenticationResponse)
Spark.setScriptData("RESPONSE_RAW", '{"Status": ""}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment