question

games avatar image
games asked

CloudScript fails when accessing URL property in object

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&access_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.

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

No, we don't block or reserve URL (or url). Can you write your payload to the log, to see what it actually contains?

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

games avatar image games commented ·
{
    "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

0 Likes 0 ·
brendan avatar image brendan games commented ·

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;

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.