Facebook Graph API获取所有用户及其状态 [英] Facebook Graph API get all users and their status

查看:514
本文介绍了Facebook Graph API获取所有用户及其状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook Graph API,我想知道是否有任何方式在一个电话中获取所有用户的列表和他们的当前状态?

I am using the Facebook Graph API and I was wondering if there was anyway to get a list of all the users and their current status in one call?

我基本上希望得到与 https://graph.facebook.com/me/friends 相同的结果,但与

I basically want the same results as https://graph.facebook.com/me/friends but with the current status included per object.

感谢您的帮助!

编辑:

这是一些澄清。如果 https://graph.facebook.com/me/friends?access_token = ... 得到我:(AKA我所有朋友的名单)

Here is some clarification. if https://graph.facebook.com/me/friends?access_token=... gets me this: (AKA a list of all my friends)

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

什么URL或FQL会得到我:(AKA是我所有朋友及其状态的列表)

what URL or FQL will get me this: (AKA a list of all my friends and their statuses)

{
  "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多个电话来获取状态。

I only want to make one call, because unlike me, most people have 100+ friends, and I don't want to have to make 100+ calls just to get statuses.

推荐答案

虽然新的批处理API 应该做你所要求的因为,我无法设法使其正常工作。看来它还是越野车。

While the new Batch API should do what you are asking for, I couldn't manage to make it work properly. It seems that it's still buggy.

现在通过 fql.multiquery ,这里有一个简单的例子:

Now to achieve this with fql.multiquery, here's a quick example:

<?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和名称,并从第二个查询获取状态消息一个。

现在这将返回更少的结果在第一个查询或第二个!因为:

Here we are getting the user id and name in the first query and getting the status messages from the second one.
Now this would return fewer results in the first query or the second! because:


  • 朋友可能尚未发布最近30天,所以它不会出现在第二个查询中(第二个查询结果集较少)。

  • 朋友可能在过去30天内发布了多个状态消息(它应该返回所有 - 最多50个!)我不知道,但如果这是情况下,第二个/将返回比第一个更多的结果。所以我只得到一个 消息(注意 break )。

  • A friend may have not posted a status message for the last 30 days, so it won't appear in the second query (second has fewer result set).
  • A friend may have posted more than one status message in the last 30 days (it should return them all - up to 50 ?!!) I'm not sure, but if this is the case then the second will/should return more results than the first one. So I'm getting only one message (notice the break).

这篇关于Facebook Graph API获取所有用户及其状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆