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

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

问题描述

Grp ...我似乎无法让fql工作。有一件事,我认为文档很旧,因为我不认为api()只喜欢一个数组。无论如何:

  $ user_id = $ facebook-> getUser(); //工作
$ access_token = $ facebook - > getAccessToken(); //工作
$ fql ='从用户的名称,其中uid ='。 $ USER_ID;
$ ret_obj = $ facebook-> api(array(
'method'=>'fql.query',
'access_token'=> $ access_token,
' query'=> $ fql,
));
print_r($ ret_obj); //不工作。实际上我得到例外

我已经尝试过api(),par可用。

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

尽管如此。

解决方案

我使用这个:

  function fql($ q,$ access_token){
//运行fql查询
$ 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);
}


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

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

does work, though.

解决方案

I use this:

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天全站免登陆