2

このコードを使用してユーザープロファイルページに投稿しています。プロファイルに投稿する場合は正常に機能しますが($ idにFacebookユーザーIDを設定します)、Facebookページ(プロファイルページではない)に投稿しようとすると)$ idにFacebookページIDを設定すると、スクリプトが機能しなくなり、次のエラーが発生しました

{"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException","code":200}}

これは私のコードです

<?php
class Facebook
{
    /**
     * @var The page id to edit
     */
    private $id = '<FACEBOOKPAGEID>';

    /**
     * @var the page access token given to the application above
     */
    private $app_access_token = "<MYAPPACCESSTOKEN>";
    /**
     * @var The back-end service for page's wall
     */
    private $post_url = '';
    /**
     * Constructor, sets the url's
     */
    public function Facebook()
    {
        $this->post_url = 'https://graph.facebook.com/' . $this->id .'/feed';
    }
    /**
     * Manages the POST message to post an update on a page wall
     *
     * @param array $data
     * @return string the back-end response
     * @private
     */
    public function message($data)
    {
        // need token
        $data['access_token'] = $this->app_access_token;
        // init
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->post_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // execute and close
        $return = curl_exec($ch);
        curl_close($ch);
        // end

        return $return;
    }
}
$facebook = new Facebook();
echo "<pre>";
echo $facebook->message(array( 'message'     => 'Message',
                          'link'        => 'http://www.mylink.com/',
                          'picture'  => 'http://www.mylink.com/pic.jpg',
                          'description' => 'My description' ) );
echo "</pre>";

?>

app_access_tokenは変更されておらず、Facebookページに投稿するためにFacebookにログインする必要がないため、app_access_tokenを使用しています。

これが私のFacebookページではなく私のプロフィールページで機能している理由について何か考えはありますか?

4

0 に答える 0