Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An active access token must be used to query information about the current user-Graph api exception

I am trying to update Facebook user status using Graph api. My code is

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

The problem is that it shows a run time error like Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. I have generated the Access Tocken. Where i have to use that to remove this exception Thanks in advance

like image 862
my name is xyz Avatar asked Aug 02 '12 11:08

my name is xyz


1 Answers

Try changing the line:

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

to

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

Also try upgrading your sdk if you are not using the latest version and if you just upgraded the sdk and it caused the trouble, than you can try to downgrade the version and check.

like image 192
happyhardik Avatar answered Nov 15 '22 21:11

happyhardik