简体   繁体   中英

How to fix “(#200) The user hasn't authorized the application to perform this action” error while posting on facebook wal

I am getting "(#200) The user hasn't authorized the application to perform this action" error when posting message on user's facebook wall. I am using facebook graph API. I have also set the "publish_actions" permission in the scope, but didn't working. My code is

require 'facebook/facebook.php';

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

$user = $facebook->getUser();

if ($user) {
    $accessToken = $facebook->getAccessToken();

    try {
        //create message with token gained before
        $post =  array(
            'access_token' => $accessToken,
            'message' => 'Test message'
        );

        $res = $facebook->api('/me/feed', 'POST', $post);

    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
} else {
    # There's no active session, let's generate one
    $login_url = $facebook->getLoginUrl(array(
        'scope' => 'publish_actions'
    ));
    header("Location: " . $login_url);
}

Can you please suggest me what i am missing in the code or in the app?

Since you mentioned that it does work for Admins, but not for anyone else, it´s very clear what the problem is: You need to go through Login Review with publish_actions - else, that permission will only work for users with a role in the App.

All the information you need about Login Review is in the docs: https://developers.facebook.com/docs/facebook-login/review

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM