PHP / Facebook-Api:更新好友列表
我正在使用官方 PHP-Facebook-Api,并且我知道如何获取用户的好友列表。它基本上是这样的:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxx',
'secret' => 'xxxxxxx',
'cookie' => true,
));
// $session is only != null, when you have the session-cookie, that is set by facebook, after the user logs in
$session = $facebook->getSession();
// you dont get a list of friends, but a list, which contains other friendlists
$friendsLists = $facebook->api('/me/friends');
// Save all Friends and FriendConnections
foreach ($friendsLists as $friends) {
foreach ($friends as $friend) {
// do something with the friend, but you only have id and name
$id = $friend['id'];
$name = $friend['name'];
}
}
在我的应用程序中,我基本上将所有朋友保存在我的数据库中,这样我就不必每次想要显示用户的所有朋友时都发出http请求。但现在我想更新好友列表。我不想删除所有朋友联系并重新保存它们。那么有人知道一个选项,如何获取自特定日期以来好友列表的更改吗?
I'm using the official PHP-Facebook-Api and I know how to get the friendlist of a user. It is basically like so:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxx',
'secret' => 'xxxxxxx',
'cookie' => true,
));
// $session is only != null, when you have the session-cookie, that is set by facebook, after the user logs in
$session = $facebook->getSession();
// you dont get a list of friends, but a list, which contains other friendlists
$friendsLists = $facebook->api('/me/friends');
// Save all Friends and FriendConnections
foreach ($friendsLists as $friends) {
foreach ($friends as $friend) {
// do something with the friend, but you only have id and name
$id = $friend['id'];
$name = $friend['name'];
}
}
In my Application I basically save all Friends in my database, so that I dont have make an http-request everytime I want to show all Friends of a user. But now I would like to update the Friendlist. I would hate to delete all friend-Connections and save them all over again. So does anybody know about an option, how to just get the changes of the friendlist since a certain date?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么你必须检查它们是否在数据库中。我建议您获取数据库中所有用户 ID 的数组,然后对照您从 API 中提取的好友进行检查。如果有新朋友,请添加他们。
Your going to have to check if they are in the database then. I suggest you get an array of all the user id's in the database and then check them against the friends you pulled from the API. If there is a new friend, add them.