Get JSON Facebook Graph API User Info with jQuery

后端 未结 2 920
抹茶落季
抹茶落季 2021-02-10 02:48

I am trying to use the graph API to get just some basic info about a user no need for authorization by the user just the public details. I am trying to use jQuery and the .getJS

相关标签:
2条回答
  • 2021-02-10 02:56

    You have to use jsonP for cross domain issues:

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

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

    0 讨论(0)
  • 2021-02-10 02:59

    It doesn't return an array, but an object. You don't need to be looping over anything.

    You can just get the name straight from the object:

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

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

    PS. you had a syntax error with $("#profile").append("<h3>"+name+"</h3>");as well (you forgot the + around name)

    0 讨论(0)
提交回复
热议问题