无法在FaceBook上获取我朋友列表的在线状态

时间:2013-04-08 19:55:30

标签: php facebook-graph-api

这是我的fql:

$fql = "SELECT uid, name, online_presence, status 
         FROM user 
        WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = '".$user_id."') ";

online_presence值始终返回null

2 个答案:

答案 0 :(得分:0)

您的查询中有错误...

只需替换

WHERE uid IN

WHERE 2 IN

<强>查询

$fql = "SELECT uid, name, online_presence, status 
         FROM user 
        WHERE 2 IN ( SELECT uid2 FROM friend WHERE uid1 = '".$user_id."') ";

SQLFiddle Demo

答案 1 :(得分:0)

如果您尝试在没有Facebook访问令牌的情况下查询Facebook,则无法检索online_presence键值。例如:

SELECT uid, name, online_presence, status FROM user WHERE uid IN (4,5,6)

如果没有设置访问令牌,则返回:

{
  "data": [
    {
      "uid": 4, 
      "name": "Mark Zuckerberg", 
      "online_presence": "", 
      "status": null
    }, 
    {
      "uid": 5, 
      "name": "Chris Hughes", 
      "online_presence": "", 
      "status": null
    }, 
    {
      "uid": 6, 
      "name": "Dustin Moskovitz", 
      "online_presence": "", 
      "status": null
    }
  ]
}

然而,在设置访问令牌的情况下,返回:

{
  "data": [
    {
      "uid": 4, 
      "name": "Mark Zuckerberg", 
      "online_presence": "offline", 
      "status": null
    }, 
    {
      "uid": 5, 
      "name": "Chris Hughes", 
      "online_presence": "offline", 
      "status": null
    }, 
    {
      "uid": 6, 
      "name": "Dustin Moskovitz", 
      "online_presence": "offline", 
      "status": null
    }
  ]
}

确保您正在设置有效的Facebook访问令牌(在PHP中使用官方Facebook SDK,如下所示:$facebook->setAccessToken($your_access_token);)并具有访问数据的相应权限。

权限可能是两个回复中“状态”返回null的原因。我不是扎克伯格先生的朋友。