-1
if($user_gender == "male")
{
$fql_query_result = file_get_contents("https://graph.facebook.com/fql?q=SELECT+uid%2C+name+FROM+user+where+uid+IN+(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20=%20me())%20and%20sex='female'ORDER%20BY%20rand%20()%20LIMIT%201&access_token=".$access_token);
}
else
{
$fql_query_result = file_get_contents("https://graph.facebook.com/fql?q=SELECT+uid%2C+name+FROM+user+where+uid+IN+(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20=%20me())%20and%20sex='male'ORDER%20BY%20rand%20()%20LIMIT%201&access_token=".$access_token);
}

在 Graph Api Explorer 中显示

{
  "data": [
    {
      "uid": 100001242402868, 
      "name": "Don Omer"
    }
  ]
}

如何从上述数据中提取 UID,以便我们可以显示他/她的头像

$friend_pic = imagecreatefromjpeg("http://graph.facebook.com/".$fql_query_result['uid']."/picture?type=normal");

我正在尝试创建一个名为“谁会嫁给我”的应用程序。

提前致谢

4

1 回答 1

0

您可以在一个查询(和一个 API 调用)中完成这一切。尝试这个:

$query = 'SELECT uid, name, sex, pic FROM user WHERE 
            uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 
            AND NOT ( sex IN (SELECT sex FROM user WHERE uid = me())) 
          ORDER BY rand () LIMIT 1';

快速而肮脏的方法是:

$url = "https://graph.facebook.com/fql?q=" . urlencode($query) . 
         "&access_token=" . $access_token;
$spouse = json_decode( file_get_contents ($url));
printf('<p>You should marry %s. <img src="%s" /></p>', 
       $spouse->data[0]->name, 
       $spouse->data[0]->pic
       );

但是您应该真正使用PHP SDK,因为它更加健壮。

于 2012-08-30T19:39:11.183 回答