我一直在尝试在页面提要上发布消息和图像。我不断收到错误消息
(#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' ];
}
}
?>
提前致谢。