【问题标题】:Publishing to a page's feed - everything seems ok, but the post doesn't appear发布到页面的提要 - 一切似乎都很好,但帖子没有出现
【发布时间】:2011-09-20 15:23:15
【问题描述】:

我想做以下(简单的)事情: - 编写一个将消息发布到页面提要的 PHP 类

我创建了一个 Facebook 应用,获得了以下操作的授权令牌:

scope=publish_stream,offline_access,read_stream,manage_pages

一切正常,消息发布正常,返回结果如下:

{"id":"pageid_newmessageid"}

但是,消息不会发布到指定页面的墙上。此外,当我尝试访问 https://graph.facebook.com/pageid/feed?access_token=token 时,此消息不存在。

有什么想法吗?

PHP 代码:

<?php

class Facebook
{       
    /**
     * @var The page id to edit
     */
    private $page_id = 'pageid';    

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

    /**
     * @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
        print_r($return);
        return $return;        
    }
}

$facebook = new Facebook();

$facebook->message(array( 'message'     => 'Some messag', 
                          'link'        => 'http://www.google.com', 
                          'description' => 'Full description explaining whether the header'));
?>

【问题讨论】:

    标签: php facebook-graph-api


    【解决方案1】:

    Daniel,我在 javascript 中使用此方法并使用 to: 参数来定位帖子所在的位置。

            function DBSthis() {
             FB.ui({ method: 'feed', 
        message: '',
            //caption: 'This is the Caption value.',
            //name: 'Testing JS feed dialog on ShawnsSpace',
            //link: 'http://shawnsspace.com?ref=link',
            to: '157690324292542',
            //description: 'Testing property links, and action links via Feed Dialog Javascript SDK',
            //picture: 'https://shawnsspace.com/ShawnsSpace.toon.nocolor..png',
            //properties: [{ text: 'Link Test 1', href: 'http://shawnsspace.com?ref=1'},
                        //{ text: 'Link Test 2', href: 'http://shawnsspace.com?ref=2'},
                            //{ text: 'Link Test 3', href: 'http://shawnsspace.com?ref=3'},
                            //{ text: 'Link Test 4', href: 'http://shawnsspace.com?ref=4'}
                            //],
            actions: [
            { name: 'Shawn', link: 'http://ShawnsSpace.com'}
            ]       
            });
            };
    

    【讨论】:

      猜你喜欢
      • 2014-06-14
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 2021-02-27
      相关资源
      最近更新 更多