开发者

Help| Exception: 200: The user hasn't authorized the application to perform this action

I have test my app before, and It worked I have managed to post to my page wall. But now after I have changed the cod开发者_开发问答e and removed the permissions, and logged in again it didn't work and trowed this exception:

Exception: 200: The user hasn't authorized the application to perform this action

Code:

if(isset($_POST['submit'])){

try {
//$facebook = new Facebook(###, ###);


$facebook->api_client->session_key = '###';//I  got this by a tutorial once but I    can't seem to get a new one, is there any way of getting one automatically?
$response = $facebook->api(array(
  'method' => 'stream.publish',
  'message' => 'Test from dreafmhosters.com',
  'target_id' => ##mypageid###;
));
} catch(Exception $e) {

echo $e . "<br />";
}
}
?>

Any solutions?


There is a lot of problem in the code. The code is a bit outdated. It wont work properly with the new graph api. Currently facebook it running Graph API version 3.0.0. Here is a sample code to post properly to the user's wall:

<?php
    //facebook application
    //set facebook application id, secret key and api key here
    $fbconfig['appid' ] = "123456392899383";
    $fbconfig['api'   ] = "97eb2asdfasdf3f20d4421b0fe8c1b2";
    $fbconfig['secret'] = "5c1d4asdfasdf71b59806b69c386b2ca";

    //set application urls here
    $fbconfig['baseUrl']    =   "http://www.your-url.com/";
    $fbconfig['appBaseUrl'] =   "http://apps.facebook.com/appname/"; 

    $uid            =   null; //facebook user id

    try{
        include_once "facebook.php";
    }
    catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));

    //Facebook Authentication part
    $session = $facebook->getSession();
    $loginUrl = $facebook->getLoginUrl(
            array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'req_perms' => 'email,publish_stream,status_update,user_birthday,user_location,user_work_history'
            )
    );

    $fbme = null;

    if (!$session) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    }
    else {
        try {
            $uid      =   $facebook->getUser();
            $me     =   $facebook->api('/me');
    $uid      =   $facebook->getUser();
    $me     =   $facebook->api('/me');
    $message_details = array(
    'message'=> 'Friends if you see this post, dont click/comment/like it. This is UNDER DEVELOPMENT',
    'link'=> 'http://apps.facebook.com/appurl',
    'name'=> 'Application Name',
    'picture'=> 'http://www.yoururl.com/image.jpg',
    'actions'=> array('name'=>'use Application','link'=>'http://apps.facebook.com/appurl'),
    'description'=> 'A FB application under development by me.',
);
$upload_message = $facebook_client->api('/feed', 'post', $message_details);
        } catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
            exit;
        }
    }

    function d($d){
        echo '<pre>';
        print_r($d);
        echo '</pre>';
    }
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜