Grr ......我似乎无法让fql正常工作。有一件事,我认为文档是旧的,因为我不认为api()只喜欢一个数组。无论如何:
$user_id = $facebook->getUser();//works
$access_token = $facebook->getAccessToken();//works
$fql = 'SELECT name from user where uid = ' . $user_id;
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'access_token' => $access_token,
'query' => $fql,
));
print_r($ret_obj);// dont work. actually I get exceptions
我已经为api()尝试过各种各样的params组合,但没有用。
$user = curl('https://graph.facebook.com/'.$user_id.'?access_token='.$access_token);
确实有用。
答案 0 :(得分:6)
我用这个:
function fql($q, $access_token) {
// Run fql query
$fql_query_url = 'https://graph.facebook.com'
. '/fql?q='. urlencode($q)
. '&access_token=' . urlencode($access_token);
$fql_query_result = file_get_contents($fql_query_url);
$length = strlen(PHP_INT_MAX);
$fql_query_result = preg_replace('/"(user_id)":(\d{' . $length . ',})/', '"\1":"\2"', $fql_query_result);
return json_decode($fql_query_result, true);
}