Reputation: 3
I'm building one of my first facebook apps, and I'm in a bit of a bind as to the most efficient way to solve this problem:
My app's mySQL db has a table containing users, and a table containing activities. I need to be able to show a user which of their friends is participating in which activity. Many users can participate in each activity, but a user can only participate in one activity.
What is the best way to approach this problem? Is there a way to query FB for my user's friends, compare that to my table of users, take the matches and return their selected activities to the user efficiently enough to not take for ever to load? If anyone could point me in the right direction for this it would be much appreciated.
Upvotes: 0
Views: 201
Reputation: 12721
You can query FB for the user's friends. But there is no reason to query for all of their friends. You probably want to filter it on friends that are using your app. If a friend isn't using your app, they probably have no activity to link to.
$query = 'SELECT uid, name FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = [user ID] )
AND is_app_user=1';
$fqlresult = $facebook->api_client->fql_query($query);
Upvotes: 0
Reputation: 8915
Once you have the logged-in user's Facebook ID and an authorized Facebook Session, you can query FB for the user's friends using the graph API. You can click the example link to see the Graph API response for your own Facebook account.
Here's the relevant page in the API docs: https://developers.facebook.com/docs/reference/api/friendlist
Here's the API overview: https://developers.facebook.com/docs/api
Since your app is in PHP, you can grab the official php SDK here and get to work! https://github.com/facebook/php-sdk/
Upvotes: 2