I'm trying to use CloudScript to get the URL of my Facebook profile picture so I can set it as my PlayFab Avatar.
/*{ // This is the JSON structure returned by the http request "picture": { "data": { "height": 50, "is_silhouette": false, "url": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10155832140626538&height=50&width=50&ext=1537585061&hash=AeRvbpI6EulgctDz", "width": 50 } }, "id": "10155832140626538" }*/ var url = "https://graph.facebook.com/me/?fields=picture&type=square∾cess_token="+authToken; var method = "get"; var contentBody = ""; var contentType = "application/json"; var headers = {}; var responseString = http.request(url,method,contentBody,contentType,headers); var payload = JSON.parse(responseString); return (((payload || {}).picture || {}).data || {}).url;
I can access the "picture" and "data" property of the JS object, but never the "url". I can even access the "height", "is_silhouette", and "width" properties by replacing "url" with those properties.
But ... when I access the "url" property, the code stops working, throwing
{ "FunctionResult": null, "Logs": null, "ExecutionTimeSeconds": 0, "MemoryConsumedBytes": 0, "APIRequestsIssued": 0, "HttpRequestsIssued": 0, "Error": { "Error": null, "Message": "There was a problem running testPic. Check your arguments and try again.", "StackTrace": null } }
Is PlayFab blocking or reserving the "url" keyword? I know it's not a JS thing because JS doesn't behave this way, and the code works fine outside of PlayFab.
Answer by Brendan · Aug 23, 2018 at 06:11 AM
No, we don't block or reserve URL (or url). Can you write your payload to the log, to see what it actually contains?
{ "FunctionResult": null, "Logs": [ { "Level": "Debug", "Message": "{\"picture\":{\"data\":{\"height\":50,\"is_silhouette\":false,\"url\":\"https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10155832140626538&height=50&width=50&ext=1537597911&hash=AeSK7VTnDou3sTUJ\",\"width\":50}},\"id\":\"10155832140626538\"}", "Data": null } ], "ExecutionTimeSeconds": 0.193594, "MemoryConsumedBytes": 32456, "APIRequestsIssued": 0, "HttpRequestsIssued": 1, "Error": null }
It works fine on a JS editor:
https://www.w3schools.com/code/tryit.asp?filename=FUJMM3FECNEG
Actually, I'm finding that you get the same result trying to return is_silhouette. The problem is due to the return being unable to handle the value itself. It works for me if you stringify the value you're returning:
var urlString = JSON.stringify(payload.picture.data.url);
return urlString;