I am trying to get a leaderboard from Cloudscript and then for each entry get userdata. I think my issues are with json but the result when I run from the client is "JSON must represent an object Type". BTW I am aware of limits on number of requests per Cloudscript call, this would be for a small excerpt of the leaderboard. Can anyone help please!
Here is the client code.
PlayFabClientAPI.ExecuteCloudScript( new ExecuteCloudScriptRequest() { FunctionName = "getLeaderboard", FunctionParameter = new { leaderboardName = leaderboardName, maxResults = MaxRequests, start = start }, }, result => { List<PlayerData> list = JsonUtility.FromJson<List<PlayerData>>(result.FunctionResult.ToString()); Debug.Log(list); }, error => { Debug.Log(error); } );
Here is the cloudscript code
// Get leaderboard and return list of players handlers.getLeaderboard = function (args, context) { var leaderboardName= args.leaderboardName; var maxResults = args.maxResults; var start = args.start; var request = { StatisticName: leaderboardName, StartPosition: start, MaxResultsCount: maxResults }; var response = server.GetLeaderboard(request); var leaderBoard = response.Leaderboard; var playerList = []; for (var i=0; i<leaderBoard.length; i++) { var entry = leaderBoard[i]; var request = { PlayFabId: entry.PlayFabId }; var response = server.GetUserData(request); var playerData = response.Data["Player"].Value; var myPlayerObject = JSON.parse(playerData); playerList.push(myPlayerObject); } return playerList; };