我如何在 php api 中使用 FQL?和访问令牌 [英] How do i use FQL with php api? and access token

查看:18
本文介绍了我如何在 php api 中使用 FQL?和访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Grr...我似乎无法让 fql 工作.一件事,我认为文档很旧,因为我不认为 api() 只喜欢一个数组.总之:

Grr... I cant seem to get fql working. One thing, I think the docs are old because i dont think api() likes just an array. Anyway:

$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() 的各种参数组合,但无济于事.

I've tried all kinds of combinations of params for api(), to no avail.

$user = curl('https://graph.facebook.com/'.$user_id.'?access_token='.$access_token);

虽然有效.

推荐答案

我用这个:

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);
}

这篇关于我如何在 php api 中使用 FQL?和访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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