I’m working on a facebook app with JS SDK…
I want to create a function that makes an API call to the Graph API:
This is what I got:
function a(reference){
FB.api('/me', function(respond){
var it = respond.reference[0].name;
alert(it);
});
}
I try executing it this way but it doesn’t work.
a("inspirational_people");
So you’re feeding the text string “inspirational_people” into your function, and you want to access a property of the response object having that very name?
That’s quite easy, basic JavaScript syntax: Every property that you can access via
object.propertyNameyou can also access asobject["propertyName"].So in your case, since you want to access
response.inspirational_people[0].name, it’sresponse[reference][0].name– the actual string value of reference is evaluated at runtime, and you should end up having what you wanted.