playFab - How to make it work?

Hi guys,

Since the gpgs is not working due to conflicting plugins, I’m giving PlayFab a go. But I haven’t found a lot Corona specific tutorials for it.

I got the user logged in correctly and would now like to upload his score to the PlayFab server. This is the code provided on the PlayFab documentation:

POST https://{{TitleID}}.playfabapi.com/Client/UpdatePlayerStatistics Content-Type: application/json X-Authentication: \<user\_session\_ticket\_value\>{ "Statistics": [{ "StatisticName": "Points", "Version": 1, "Value": 600 }, { "StatisticName": "Wins", "Version": 0, "Value": 16 }, { "StatisticName": "Stars", "Value": 7 }] }

So I should use REST API call right? But how exactly?

This is what I’ve got right now in lua code:

function M.uploadHighScore(highscore) local function networkListener( event ) if ( event.isError ) then print( "Network error: ", event.response ) else print ( "Upload complete!" ) end end local headers = {} headers["Content-Type"] = "application/json" headers["X-API-Key"] = "13b6ac91a2" local params = {} params.headers = headers -- Tell network.request() to get the request body from a file: params.body = { filename = "object.json", baseDirectory = system.DocumentsDirectory } network.request( "https://XXXX.playfabapi.com/Client/UpdatePlayerStatistics", "POST", networkListener, params ) end

I basically got this from the Corona docs and filled in the correct address (I changed the XXXX in the request). But other than that, I don’t really know what to do with it.

  • First of all, how should I get the user_session_tocken_value?
  • The values I want to push, do they have to be in the params.body table?
  • Should the body include a json file or can I just include one variable? (because I only need one)

I’m sorry, I have never used the REST API before  :frowning:

No REST API calls were needed. PlayFab provided a nice set of functions for us! This is how I get the leaderboards:

 print("updating highscore") local request = { Statistics = { { StatisticName = "highscore", Value = score } } } PlayFabClientApi.UpdatePlayerStatistics(request, function(result) print("Updated Stats Successfully!") end, function(error) print("Error Updating Stats!") end)

No REST API calls were needed. PlayFab provided a nice set of functions for us! This is how I get the leaderboards:

 print("updating highscore") local request = { Statistics = { { StatisticName = "highscore", Value = score } } } PlayFabClientApi.UpdatePlayerStatistics(request, function(result) print("Updated Stats Successfully!") end, function(error) print("Error Updating Stats!") end)