php – 必须使用活动访问令牌来查询有关当前用户 – Graph api异常的信息

前端之家收集整理的这篇文章主要介绍了php – 必须使用活动访问令牌来查询有关当前用户 – Graph api异常的信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Graph api更新Facebook用户状态.我的代码
<?PHP 
    require 'facebook.PHP'; 
    $facebook = new Facebook(array( 
    'appId' =>'389694921095423','secret' =>'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX','cookie' => true
    )); 
    $access_token = $facebook->getAccessToken();
    echo($access_token);
    $me = null; 

    try 
    { 
        $uid = $facebook->getUser(); 
        $me = $facebook->api('/me'); 
        echo "Welcome User: " . $me['name'] . "<br />"; 
        //access permission
        $permissions_needed = array('publish_stream','read_stream','offline_access','manage_pages');
        foreach($permissions_needed as $perm) 
        {  
            if( !isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1 )
            {    
            $login_url_params = array(
                'scope' => 'publish_stream,read_stream,offline_access,manage_pages','fbconnect' =>  1,'display'   =>  "page",'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']      
                );    
            $login_url = $facebook->getLoginUrl($login_url_params);   
            header("Location: {$login_url}");
            exit(); 
            }
        }
        //Access permission

        $post_id = $facebook->api("/$uid/Feed","post",array("message"=>"Hello World!")); 
        if(isset($post_id)) 
        {
            echo "A new post to your wall has been posted with id: $post_id"; 
        }
    } 
    catch (FacebookApiException $e) 
    { 
        echo($e); 
    } 
?>

问题是它显示运行时错误,如致命错误:未捕获OAuthException:必须使用活动访问令牌来查询有关当前用户的信息.我已经生成了Access Tocken.我必须使用它来删除此异常
提前致谢

尝试更改线路:
$me = $facebook->api('/me');

$me = $facebook->api('/'.$uid);

如果你没有使用最新版本,如果你刚刚升级了sdk并且它造成了麻烦,那么也尝试升级你的sdk,而不是你可以尝试降级版本并检查.

原文链接:https://www.f2er.com/php/136161.html

猜你在找的PHP相关文章