How to use facebook API while getting friends list in javascript

I am not familiar with using the Javascript SDK for Facebook. My story is when I access a website. It displays all my friends (pic. & Name) on the web page. I registered the Facebook API and the application identifier. I posted the website URL http: // localhost: 81 / because I am testing my local machine. Do you have a good example website or good examples? Please share with me Thank you.

+4
source share
2 answers

Your application must first use the required permissions, for example,

user_birthday, friends_birthday, user_location , friends_location... 

(for additional permissions)

Get current user information:

 FB.api('/me', function(response) { // Stuff here }); 

Get information about current friends of users:

 FB.api('/me/friends', function(response) { // Stuff here }); 

You will get an answer like:

 {data: [{id: "FRIEND1_ID", name: "FRIEND1_NAME"}, {id: "FRIEND2_ID", name: "FRIEND2_NAME"}]....} 

If you want to get additional properties of your friends, use the FIELDS parameter, for example

 FB.api('/me/friends', {fields: 'name,id,location,birthday'}, function(response) { // Stuff here }); 

If you want to get information about another user:

 FB.api('/FRIEND1_ID', function(response) { // Stuff here }); 

Try Sample Site

+12
source

Direct Access Method:

Log in to Facebook with your name. If you need an “access token,” click “Advanced Permissions” and check the “read_friendlist” box to get your access token, then send your request. You may need to “Allow” access, so just follow the prompts. Voila! You now have usernames for everyone in your friends list. The "username" parameter in the request will give you the contact message "message to this person" and you will add @ facebook.com and send them a message. Very simple.

http://developers.facebook.com/tools/explorer?fql=SELECT%20username%20FROM%20user%20WHERE%20uid%20IN%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me% 28% 29% 29% 20ORDER% 20BY% 20name

-SAB

0
source

Source: https://habr.com/ru/post/1398918/


All Articles