Retrieve JSON Facebook Graph API user information using jQuery

I am trying to use the graph API to get only some basic information that the user does not need to authorize the user only public information. I am trying to use jQuery and .getJSON to get the data and parse it, but it is hard for me to find ways to access the key value pairs that I want.

I want to have something like

var fburl = "http://graph.facebook.com/USER/callback=?"

$.getJSON(fburl, function(data){
  $.each(data, function(i,item){
     var name = item.user["name"];
     $("#profile").append("<h3>"name"</h3>");
  });
});

ive tried things like item.name and a bunch of others, which I thought were potential syntax options, but still getting undefined.

Is there something wrong with this approach. I only have experience using JSON with the twitter API, which works great with the above approach.

When consolidating log data, I get something like this

first_name: "First"
gender: "male"
id: "8977344590"
etc...
name: "Full Name"
+5
2

, . .

:

$.getJSON(fburl, function(data){
     var name = data["name"];
     $("#profile").append("<h3>"+name+"</h3>"); 
});

example: http://jsfiddle.net/niklasvh/Wm9M3/

PS. $("#profile").append("<h3>"+name+"</h3>"); ( + name)

+3

jsonP :

$.get(fburl, function(data){
    console.log(data);
    alert(data.name);
},'jsonp');

Fiddle: http://jsfiddle.net/maniator/34m9J/

+2

All Articles