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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With