Getting an Facebook user profile data with Javascript

前端 未结 3 1773
别那么骄傲
别那么骄傲 2020-12-09 09:52

I need to get a facebook user uid , gender, photo and other profile data with Javascript.

I remember there was a method to get an user object with .id, .gender, .pho

3条回答
  •  甜味超标
    2020-12-09 10:27

    Update: I added a little more detail to the answer:

    First, you need to call FB.init and add your app id:

    FB.init(
    {
        appId  : APP_ID,
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true  // parse XFBML
    });
    

    Next, check if there is a session open (i.e., the user is logged in)

    if(FB.getSession() != null) {
    

    And query the details by:

        FB.api('/me', function(response) 
        {
            alert ("Welcome " + response.name + ": Your UID is " + response.id); 
        });
    }
    

    You will also need to add

    to the of your page, and load

    The user profile picure can be accessed as http:/graph.facebook.com/USERID/picture/

    Check the Graph API reference here: http://developers.facebook.com/docs/reference/api/user/

    and the FB SDK reference here: http://developers.facebook.com/docs/reference/javascript/

提交回复
热议问题