开发者

efficient solution how to? (Facebook & SQL)

开发者 https://www.devze.com 2023-01-31 00:28 出处:网络
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:

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 acti开发者_如何学编程vity, 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.


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/


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号