简体   繁体   中英

Retrieve Facebook friends with Javascript API when user is not logged in but Facebook ID is known?

I have my site set up so that a user can sign up or log in with Facebook or with a separate password. There is a screen that shows the user his or her Facebook friends on the site, however, I can't retrieve the friend information unless the user is logged in with Facebook.

Currently, I have a Facebook login button set up in the spot where the friend previews would show up if the user were logged in. The button basically tells the user to login with Facebook to see his or her friends, but I'm wondering if there's a better solution.

Since I'm saving the user's unique Facebook ID in a database, is there a way that I can retrieve his or her friends using only the Facebook ID but without the user being logged in?

You can only get the friends of the user with a User Token of that specific user and the following endpoint: /me/friends

If you want to get the friends of the user while he is offline, you have to store his User Token or the list of his friends. If you store the list of his friends, you should refresh the list whenever the user goes online again or it may not be up to date.

Be aware that you can only get friends who authorized your App with the user_friends permission too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM