在没有用户帐户的情况下发布到Facebook页面

时间:2012-04-24 16:06:02

标签: php facebook

我必须遵循以下代码:

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

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

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

var_dump($facebook->message(array( 'message'     => 'A sample message' ) ) );

现在,当我执行代码时,返回boolean false。有人可以解释我如何在没有帐户的情况下这样做,因为我只想要一个页面,并且能够用PHP发布它吗?

谢谢!

0 个答案:

没有答案