我一直在寻找我的问题的答案,但到目前为止我得到了以下结果:
https://graph.facebook.com/the_user_id?fields=name,picture
我需要能够显示/打印一组用户的姓名和图片,我知道他们的ID。需要什么代码来获取这些数据,然后将其发布到php/html页面上?当然,这意味着如果我想显示10个用户,我将输入10个不同的ID(阅读smtg关于数组列表的内容?)。请注意,对于当前用户,我并不需要这样做。
提前感谢您的回复。
发布于 2012-08-16 03:57:02
您需要在php中使用file_get_contents ( http://uk3.php.net/file_get_contents )或curl,并向url发出如下请求:
https://graph.facebook.com/?ids=id1,id2,id3&fields=name,picture(将id1、id2替换为您的ids)
这将返回一个json对象。然后,您需要对其进行解码( http://uk3.php.net/json_decode )和循环,然后访问该信息
这应该可以让你开始
// people array uses the users id as the key and the dessert as the value. The id is then used in the query to facebook to select the corresponding value from this array
$people = array("id1"=>"favourite "dessert", "id2"=>"favourite dessert", "id3"=>"apple pie");
$json = file_get_contents('https://graph.facebook.com/?ids=id1,id2,id3&fields=id,name,picture');
$json = json_decode($json);
foreach($json as $key=>$person){
echo '<p><img src="'.$person->picture.'" alt="'.$person->name.'" />';
echo $person->name.'\'s favourite dessert is '.$people[$person->id'];
echo '</p>';
}我在这里对请求进行了批处理,或者您也可以为每个用户执行10个单独的查询,但这样做有点毫无意义且效率低下
发布于 2012-08-16 03:57:53
最简单的方法是使用FQL查询:
SELECT first_name, last_name, pic, uid FROM user WHERE uid IN
(Known_ID_1, Known_ID_2, ... Known_ID_n)尽管您也可以直接调用https://graph.facebook.com/fql?q=URL_ENCODED_QUERY,但如果您使用PHP语言,最简单的方法就是安装PHP SDK
https://stackoverflow.com/questions/11976077
复制相似问题