我正在使用Facebook Graph API,我想知道是否还有一个电话中的所有用户及其当前状态列表?
我基本上希望得到与https://graph.facebook.com/me/friends相同的结果,但每个对象包含当前状态。
感谢您的帮助!
编辑:
以下是一些澄清。如果https://graph.facebook.com/me/friends?access_token=...
让我这样:( AKA我所有朋友的名单)
{
"data": [
{
"name": "Foo",
"id": "1"
},
{
"name": "Bar",
"id": "2"
},
{
"name": "Foo Bar",
"id": "3"
},
{
"name": "Bar Foo",
"id": "4"
}
]
}
什么网址或FQL会让我这样:( AKA我所有朋友及其状态的列表)
{
"data": [
{
"name": "Foo",
"id": "1"
"status": "This is my current status!"
},
{
"name": "Bar",
"id": "2"
"status": "This is my current status!"
},
{
"name": "Foo Bar",
"id": "3"
"status": "This is my current status!"
},
{
"name": "Bar Foo",
"id": "4"
"status": "This is my current status!"
}
]
}
我只想拨打一个电话,因为与我不同,大多数人都有100多个朋友,而且我不想只是为了获得状态而拨打100多个电话。
答案 0 :(得分:8)
虽然新的Batch API应该按照您的要求行事,但我无法使其正常运行。它似乎仍然是马车。
现在用fql.multiquery
来实现这个目的,这是一个简单的例子:
<?php
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$my_url = "REDIRECT_URL";
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
$queries = '{"query1":"SELECT uid,name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me())","query2":"SELECT uid,message FROM status WHERE uid IN (SELECT uid FROM #query1)"}';
$multiquery = "https://api.facebook.com/method/fql.multiquery?queries=" . urlencode($queries) . "&format=json&" . $access_token;
$res = json_decode(file_get_contents($multiquery), TRUE);
$final = array();
foreach( $res[1]['fql_result_set'] as $i=>$message_arr ) {
foreach( $res[0]['fql_result_set'] as $j=>$friend ) {
if( $message_arr['uid'] == $friend['uid'] ) {
$friend['message'] = $message_arr['message'];
$final[] = $friend;
break;
}
}
}
print_r($final);
?>
这里我们在第一个查询中获取用户ID和名称,并从第二个查询中获取状态消息 现在,这将在第一个查询或第二个查询中返回更少的结果!因为:
break
)。答案 1 :(得分:3)
尝试以下fql:
Select uid, message from status where uid in (select uid2 from friends where uid1 = [active user id])
请确保限制为特定日期,因为默认情况下,这将返回最近50次更新/或最近30天的活动。
答案 2 :(得分:0)
嗨,你只需要获得user_status or friend_status的扩展许可,对我的任何调用对象都会获取用户当前状态...
json_decode(file_get_contents('https://graph.facebook.com/me/friends?access_token='.$cookie['access_token']));
答案 3 :(得分:0)
感谢@mgilson的回答,这可以合并为一个FQL语句,如下所示:
SELECT status_id,uid,message FROM status WHERE uid IN(SELECT uid FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()))
我发现的魔法是请求friends_status
许可,该许可将从公开帖子打开给朋友和其他人,这有助于复制墙壁的感觉。