Getting an Facebook user profile data with Javascript

前端 未结 3 1771
别那么骄傲
别那么骄傲 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:20

    The function FB.getSession() used in the accepted answer to this question in 2011 is now (2012) deprecated and removed from the Facebook JS SDK.

    You can still discover the user's Facebook ID with the getLoginStatus() method like this:

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        alert ("Your UID is " + response.authResponse.userID);
      }
    });
    

    Note: you still have to init the Facebook API and put the fb-root element in your HTML, like Aleadam explained in the accepted answer.

提交回复
热议问题