簡體   English   中英

Facebook牆貼使用PHP OAuth錯誤

[英]Facebook wall post using php oauth error

這是我使用oauth撰寫的FACEBOOK留言牆的代碼,

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

    /**
     * @var the page access token given to the application above
     */
    private $page_access_token = 'CAAFxzhxYP6kBAJZADenicftONfBf10ZBAv6uziZAUz4ZAlyOzIpkYZBtnonqarkih7TyT3N7kS3S6APvS80MWJRGjxgCGHjoZAapTZCqnJf8ltymJK27D8eG57cFqNQZBsCIu6xKdjXjHZBZCXQgB8hT0pIMfLoiHYJo7t9ZAXAZAVru7QZDZD';

    /**
     * @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->page_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->page_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();

$facebook->message(array( 'message'  => 'The status header',
                          'link'        => 'http://theurltopoint.to',
                          'picture'  => 'http://thepicturetoinclude.jpg',
                          'name'        => 'Name of the picture, shown just above it',
                          'description' => 'Full description explaining whether the header or the picture') );

echo "<pre>";
print_r($facebook->message());
echo "</pre>";                        

?>

我遇到了這樣的錯誤{"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}

而且該帖子也不會發布到牆上。 幫我解決這個問題

謝謝

您錯過了這一行:

...
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM