json - Facebook Graph API 获取所有用户及其状态

标签 json facebook facebook-graph-api

我正在使用 Facebook Graph API,我想知道是否可以在一次调用中获取所有用户及其当前状态的列表?

我基本上想要与 https://graph.facebook.com/me/friends 相同的结果但包含每个对象的当前状态。

感谢您的帮助!

编辑:

这里有一些说明。如果 https://graph.facebook.com/me/friends?access_token=... 让我得到这个:(也就是我所有 friend 的列表)

{
  "data": [
    {
      "name": "Foo",
      "id": "1"
    },
    {
      "name": "Bar",
      "id": "2"
    },
    {
      "name": "Foo Bar",
      "id": "3"
    },
    {
      "name": "Bar Foo",
      "id": "4"
    }
  ]
}

什么 URL 或 FQL 会让我得到这个:(也就是我所有 friend 及其状态的列表)

{
  "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 多个 friend ,我不想为了获得状态而打 100 多个电话。

最佳答案

虽然新Batch API应该做你要求的,我无法让它正常工作。看来还是有bug。

现在用 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 和名称,并从第二个查询中获取状态消息。
现在这将在第一个或第二个查询中返回更少的结果!因为:

  • friend 可能还没有为 last 30 days 发布状态消息, 因此它不会出现在第二个查询中(第二个查询的结果集较少)。
  • 一位 friend 在过去 30 天内可能发布了不止一条状态消息(它应该全部返回 - 最多 50 条?!!)我不确定,但如果这是情况下,第二个将/应该返回比第一个更多的结果。所以我只收到一条消息(注意中断)。

关于json - Facebook Graph API 获取所有用户及其状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5479819/

相关文章:

java - Spring RestTemplate boolean 值反序列化

c# - 对 JSON 数据进行 SQL LIKE 查询

ios - Unity和Facebook 6.0:解决主机超时:Integrated-plugin-canvas-rsrc.fbsbx.com

facebook - 我可以强制刷新 Facebook 对象的图像 URL 吗?

iOS :How to get Facebook Album Photo's Picker

facebook - 仅通过别名查找组 ID

c# - 在 .NET 2.0 中序列化为 JSON

php - 从 url/超链接发布 Open Graph Story

android - Facebook 个人资料图片 Android 返回 null

json - Golang json解码返回空