Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an Facebook user profile data with Javascript

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, .photo but I haven't got a copy of the API call and I can't find an explanation in the documentation.

How do I get the user UID and gender with Javascript ?

Thanks

like image 840
lisovaccaro Avatar asked May 01 '11 05:05

lisovaccaro


People also ask

How do I find Facebook user data?

You can get user data by using the Facebook Graph API if the user has given their permission to share their data and your app has the appropriate permissions to receive this data. This topic shows you how to make a single request for data and how to have a batch of requests in a single request.

What data can I get from Facebook API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

Is the Facebook API free?

In the newest version of the Graph API (v2. 9), we're announcing features that simplify development, making it even easier to build apps and experiences with Facebook. We're providing free access to over 140 million places around the world, the same data that powers Facebook, Instagram, and Messenger.

How do I get my Facebook API user ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.


1 Answers

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.

like image 147
user327961 Avatar answered Sep 30 '22 14:09

user327961