FQL错误102需要重复查询时的用户会话 [英] FQL Error 102 Requires user session on a repeated query

查看:126
本文介绍了FQL错误102需要重复查询时的用户会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能齐全的FQL查询,但是当它第二次被触发时,我得到一个错误代码102:需要用户会话



在我的应用程序我有一个自动完成搜索的朋友。
我正在使用jquery ui自动完成与动态源使用AJAX。



这是我的PHP功能:

  function fb_buscarAmigosAutocomplete($ term ='',$ app_user = false){
$ facebook = new Facebook(array(
'appId'=> APP_ID ,
'secret'=> APP_SECRET
));

$ term = trim(strtolower($ term));

//使用权限
尝试{
$ fql =SELECT uid,name,first_name,last_name,pic_square
FROM user
WHERE uid IN
SELECT uid2
FROM friend
WHERE uid1 = me()

AND strpos(lower(name),'。$ term。')> = 0
;
if($ app_user)
$ fql。=AND is_app_user;

$ fql。=LIMIT 5;

$ param = array(
'method'=>'fql.query',
'query'=> $ fql,
'callback'= >''
);
$ result = $ facebook-> api($ param);


} catch(FacebookApiException $ e){
$ error = $ e-> getMessage();
var_dump($ e);
}

if(!empty($ result)){
$ return ['amigos'] = $ result;
$ return ['valido'] = true;
} else
$ return ['valido'] = false;

return $ return;
}

奇怪的是,这在最近2-3周内正常工作,突然间停了下来。即使是weirder,它仍然是第一次被触发,但不是第二次。由于这是异步的,所以我不明白如果是第一次,第二次,第三次,第四次触发,它有什么区别。



任何想法? >

编辑1
随着进一步的研究,我想我有一个解决方法。
这可能是因为一个错误报告 here ans discused here



我的解决方法是抓住第一个access_token,我接触到对象Facebook,然后将其附加到类的每一个实例,这样的一个这样的



第一连接

  $ facebook = new Facebook (array(
'appId'=> APP_ID,
'secret'=> APP_SECRET
));

$ uid = $ facebook-> getUser();
if($ uid){
$ _SESSION ['access_token'] = $ facebook-> getAccessToken();
}

任何其他使用api:
'appId'=> APP_ID,
'secret'= > APP_SECRET
));
$ facebook-> setAccessToken($ _ SESSION ['access_token']);
try {
$ user_info = $ facebook-> api('/'.$ uid。'?fields = id,name,first_name,last_name,email,picture');

} catch(FacebookApiException $ e){
$ error = $ e-> getMessage();
}

到目前为止,已经解决了问题



编辑2

它没有...有时我的访问令牌是一个有效的字母数字+100个字符串,这些时间可以使用。



有时候它是一个48个数字字符串,它不...我真的卡在这里

解决方案

可能发生的原因是因为 2012年12月5日 Facebook推出的突破性变化具体来说:


OAuth授权码的新安全限制



我们只允许授权代码交换访问令牌一次,并要求在创建后10分钟内交换访问令牌。这符合OAuth 2.0规范,从一开始就表示授权代码必须是短期和单次使用。有关更多信息,请查看我们的认证文档。


这就是为什么你的第一个请求工作,你的第二个请求不工作。在第二次尝试时,SDK会尝试交换用户的访问令牌的验证码。但是由于这些变化,这只能做一次。您的代码看起来应该正常工作,因为您明确保存,然后在首次收到之后设置 access_token 。确保是这样的(确认$ _SESSION var正在正确保存/检索)。如果由于某种原因,它不是,102错误是你会看到。



干杯


I have a fully functional FQL query, but when it is triggered for the second time i get an error code 102: Requires user session

On my app i have an Autocomplete Search for Friends. I am using jquery ui autocomplete with a dynamic source using AJAX.

This is my PHP Function:

function fb_buscarAmigosAutocomplete($term='',$app_user=false){
$facebook = new Facebook(array(
    'appId' => APP_ID,
    'secret'=> APP_SECRET 
));

$term=trim(strtolower($term));

//Buscar usuarios
try{
    $fql     =  "   SELECT uid,name,first_name,last_name,pic_square
                    FROM user
                    WHERE uid IN (
                        SELECT uid2
                        FROM friend
                        WHERE uid1=me()
                    )
                    AND strpos(lower(name),'".$term."') >=0
                ";
    if($app_user)
        $fql .= "   AND is_app_user";           

        $fql .= "   LIMIT 5";

        $param  =   array(
            'method'    => 'fql.query',
            'query'     => $fql,
            'callback'  => ''
        );
        $result   =   $facebook->api($param);


} catch(FacebookApiException $e){
    $error=$e->getMessage();
    var_dump($e);
}

if(!empty($result)) {
     $return['amigos']=$result;
     $return['valido']=true;
}else 
    $return['valido']=false;

return $return;
}

The weird thing is that this was working fine for the last 2-3 weeks, and all of a sudden it stopped. Even "weirder", it still works the first time it is triggered, but not the second time. Since this is asynchronous, i dont understand what difference does it make if is the first, second, third, fourth time it is triggered..

Any ideas?

Edit 1 With further research i think i got a workaround. This may be because a bug reported here ans discused here

My workaround was to catch the first access_token i get with the Object Facebook, then attach it to every single instance of the Class, something like this

First connection:

$facebook = new Facebook(array(
    'appId' => APP_ID,
    'secret'=> APP_SECRET 
));

$uid = $facebook->getUser();
if($uid){
  $_SESSION['access_token']=$facebook->getAccessToken();
} 

Any other use of the api:

$facebook = new Facebook(array(
    'appId' => APP_ID,
    'secret'=> APP_SECRET 
));
$facebook->setAccessToken($_SESSION['access_token']);
try{
    $user_info  = $facebook->api('/'.$uid.'?fields=id,name,first_name,last_name,email,picture');

} catch(FacebookApiException $e){
    $error = $e->getMessage();
}    

So far it has solved the problem

Edit 2
it did not... sometimes my access token is a valid alphanumeric +100 characters String and those times it works.

Sometimes it is a 48 only numbers String, and it doesn't... i'm really stucked here

解决方案

The reason this is likely happening is because of the December 5, 2012 "Breaking Changes" that Facebook has rolled out. Specifically:

New security restrictions for OAuth authorization codes

We will only allow authorization codes to be exchanged for access tokens once and will require that they be exchanged for an access token within 10 minutes of their creation. This is in line with the OAuth 2.0 Spec which from the start has stated that "authorization codes MUST be short lived and single use". For more information, check out our Authentication documentation.

This is why your first request works, your second doesn't. On the 2nd attempt, the SDK attempts to exchange your the user's auth code for an access token. But due to these changes, this can only be done once. Your code looks like it should be working properly, since you are explicitly saving and then setting the access_token after you first receive it. Make sure that that is the case (confirm that the $_SESSION var is being saved/retrieved properly). If for some reason it is not, the 102 error is what you will see.

Cheers

这篇关于FQL错误102需要重复查询时的用户会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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