I have the following command which will allow me to post a message on the logged in users facebook wall:
$facebook->api("/$uid/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
i.e. using the url https://graph.facebook.com/<user id goes here>/feed
But what command do I need to enter to get a list of the logged in users friends?
The url I need to use is https://graph.facebook.com/me/friends
, but I am not sure how to edit the below command to get the friends list:
$facebook->api("/$uid/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
am I supposed to do something like this (which is a complete guess)
$facebook->api("/$uid/friends", "GET", array('access_token' => 'token value goes here'));
Or am I supposed to do something else to get the friends list?
This post on SO may provide the answer you are looking for. You will need to get the friends object then do a foreach loop over it to print the results (as described in the post). Read Getting list of Facebook friends with latest API
If you have a valid session, then this should retrieve the current user's friends:
But if you don't have a valid session (or need to retrieve this offline) you need theoffline_access
permission and your code will also work.UPDATE:
Since the deprication of the
offline_access
permission, you need a long-livedaccess_token
.Please note that you can get the friends list with this FQL query too: