开发者

Update facebook page status from that page itself

I'm trying to update the status of my page (from my page). I have been successful in posting to the wall of the page with the following code:

require_once 开发者_高级运维'facebook-php-sdk/src/facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => '...',
  'secret' => '...'
));

$attachment = array(
'access_token' => "...",
'message'=> "Hello World"
);

$facebook->api('/pageId/feed','POST', $attachment);

But the post shows that I posted to the page from my account(ie: Joe Blogs) where I want it to show that it was posted by the page itself (ie: Page Name).

Or am I going about it the wrong way? Should I be trying to change the Status of the page (if possible)?

Any help would be greatly appreciated.


After many days of pulling my hair out over this one I have seemed to have solved this issue. I will explain:

The reason that my posts were coming from myself instead of the page is because the access_token I was using was from my account instead of from the page. You will need to get an access token from the page itself.

Which is explained here (http://developers.facebook.com/docs/api#auth) under 'Page impersonation'

This is how I did it.

I firstly gave my account permission to manage the pages I had by using this url:

https://graph.facebook.com/oauth/authorize?client_id=...&redirect_uri=...&scope=manage_pages

you will need to insert client_id with your app id and insert a redirect url - You'll be brought to a page witch will ask you to authorise (which you should say yes to :)

then in php I accessed details of my current account and the pages I administer with the following code:

require_once 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => '...',
  'secret' => '...'
));

$attachment2 = array(
'access_token' => "..." //this is my current user access_token
);

$page =  $facebook->api('/me/accounts', 'get', $attachment2);
print_r($page);

This will print out details about the pages you administer and access_tokens for those pages (bingo!)

you can then take that/those access_token(s) and insert it in the code that I published above and whala - it will post to your page from your page. :)


pageID should be defined as the page your trying to post to:

$pageID = "872348971237345"; //obtained from page's url

$status = $facebook->api($pageID.'/feed', 'post', $attachment);


You need to add the UID of your fan page to your api call.

I believe it should be something like:

$uid = 'your page id';
$facebook->api('/pageId/feed', 'POST', $attachment, $uid);

If no UID is provided in the call, it defaults to the session user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜