0

我一直在尝试在页面提要上发布消息和图像。我不断收到错误消息

(#1) 创建共享时出错。

仅当其他人尝试发布时才会发生这种情况。如果我,页面的所有者尝试发布它是成功的。

所以我的问题是:是否可以发布到其他用户的页面提要?

我对此进行了大量研究,但似乎找不到合理的解决方案。

这是我用来发布消息的代码:

<?php

class Photo_contest_helper extends Facebook
{
    private $_key = '***********';
    private $_secret = '***************';

    private $_page_id = '387228561388254';

    public $fb_login_url;
    public $fb_logout_url;

    public $image_id;

    public function init()
    {
        $this->connect();

        $image_id = $this->save_image();

        if( !!$image_id ) {
            $this->image_id = $image_id;
            $this->push_to_facebook( $image_id );
        }
    }

    public function save_image()
    {
        $image_id = NULL;

        if ( !!$_POST[ "image" ] || !!$_FILES ) {
            $image_id = Image_helper::save_one( $_POST[ "image" ] );
        }

        return $image_id;
    }

    public function push_to_facebook( $image_id )
    {
        $access_token = $this->get_page_access_token();

        $this->publish_photo( $access_token );
    }

    public function connect()
    {
        parent::__Construct( array( 'appId' => $this->_key, 'secret' => $this->_secret ) );

        $user = $this->getUser();

        if( !$user ) {
            $this->fb_login_url = $this->getLoginUrl( array( 'scope' => 'manage_pages,publish_actions,publish_stream,status_update' ) );
        }
        else {
            $this->fb_logout_url = $this->getLogoutUrl( array( 'next' => 'http://stormtest.co.uk/' . DIRECTORY . "home/logout" ) );
        }
    }

    public function get_page_access_token()
    {
        $accounts = $this->api( '/me/accounts', 'get' );
        $access_token = NULL;

        foreach ( $accounts[ 'data' ] as $account ) {
            if ( $account[ 'id' ] == $this->_page_id ) {
                $access_token = $account[ 'access_token' ];
            }
        }

        return $access_token;
    }

    public function publish_photo( $access_token = "" )
    {

        $params = array( 'message' => 'Competition entry',
                         'link' => 'http://stormtest.co.uk/' . DIRECTORY . '_admin/assets/uploads/images/' . $this->get_image(),
                         'caption' => 'This is my competition entry',
                         'picture' => 'http://stormtest.co.uk/' . DIRECTORY . '_admin/assets/uploads/images/' . $this->get_image() );

        if( !!$access_token ) {
            $params[ 'access_token' ] = $access_token;
        }


        try {
            $this->api( '/' . $this->_page_id . '/feed', 'post', $params );
        }
        catch( FacebookApiException $e ) {
            die( print_r( $e ) );
        }
    }

    public function get_image()
    {
        $image_model = new Image_model();
        $image_model->find( $this->image_id );

        return $image_model->attributes[ 'imgname' ];
    } 
}

?>

提前致谢。

4

1 回答 1

0

您应该使用 JavaScript SDK 将内容共享到页面。通过 API 发布到他人的墙已被禁用:

FB.ui( {
    method: 'feed',
    to: '387228561388254',
    name: "Facebook API: Tracking Shares using the JavaScript SDK",
    link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
    picture: "https://stackexchange.com/users/flair/557969.png",
    caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, callback );

使用to上面代码中的字段设置page_id,并相应地更改其他属性(但不要更改method)。

于 2013-10-02T11:07:47.683 回答