Update facebook page status from this page

I am trying to update the status of my page (from my page). I managed to send the following code to the page wall:

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 message shows that I sent my account to the page (for example, Joe Blogs), where I want it to show that it was sent by the page itself (i.e.: Page name).

Or am I mistaken about this? Should I try to change the status of the page (if possible)?

Any help would be greatly appreciated.

+2
source share
3 answers

After many days of stretching my hair over it, I seem to have solved this problem. I will explain:

The reason my messages come from me, not from the page, is because the access_token I used was from my account, not from the page. You will need to get the access token from the page itself.

What is explained here (http://developers.facebook.com/docs/api#auth) in the "Page Simulation" section

Here is how I did it.

First, I gave my account permission to manage the pages that I had with this URL:

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

you will need to insert client_id with your application id and insert the redirect URL. You will be taken to a page that asks you to allow (that you should say yes :)

then in php I got access to the data of my current account and the pages that I administer using 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 information about the pages you are administering and access_tokens for those pages (bingo!)

you can take those / those access_token (s) and paste them into the code I posted above, and whala - it will be placed on your page from the page. :)

+1
source

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

I believe this should be something like:

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

If no UID is specified in the call, the session user is used by default.

0
source

pageID should be defined as the page you are trying to send a message to:

 $pageID = "872348971237345"; //obtained from page url $status = $facebook->api($pageID.'/feed', 'post', $attachment); 
0
source

Source: https://habr.com/ru/post/926114/


All Articles