Frage

I know this question has been frequently asked but I trying to do a post on a Facebook page since 2days without any results.

Here is what I have :

  • An application, with an APP_ID and an APP_SECRET
  • A facebook page with an ID
  • My personal ID

I want to programatically post a feed on the page, and don't know how all of this works..

I tried to request via

https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APP_ID&client_secret=APP_SECRET

which gives me a access token, but when I try to

https://graph.facebook.com//feed?access_token=TOKEN

and that doesn't work.

I also tried to do that with requesting my access_token, but it needs a redirect_uri, and the token is given is the new URL and required an action (accept) permissions. That's not what I want.

I just want to publish on a page where I am the admin..

Thanks in advance.

War es hilfreich?

Lösung

There are 4 types of access token:

  1. User Access Token (Include page actions.)
  2. App Access Token (Modify and read the app settings. It can also be used to publish Open Graph actions.)
  3. Page Access Token (Specific to page actions.)
  4. Client Token (rarely used)

https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APP_ID&client_secret=APP_SECRET

What you've done is retrieve the App Access Token, which was nothing to do with page.

So, in order to post Facebook feed pages as admin, you should use User Access Token OR Page Access Token instead.

User Access Token:

You will have to go through authorization dialog to retrieve your User Access Token:

https://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=145634995501895&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html%3Fdisplay%3Dpage&response_type=token&fbconnect=1&perms=manage_pages%2Cstatus_update

Make sure you granted both manage_pages and status_update permission, as shown in the perms= parameter above. The reason can be found here: why does posting to facebook page yield "user hasn't authorized the application"

Then you do HTTP POST request (e.g. message=hello) to your page on https://graph.facebook.com/YOUR_PAGE_ID/feed?access_token=YOUR_USER_ACCESS_TOKEN

Page Access Token:

You have to use User Access Token to retrieve Page Access Token via API calls:

  1. https://graph.facebook.com/me/accounts?access_token=YOUR_USER_ACCESS_TOKEN (Get all pages token)

  2. https://graph.facebook.com/YOUR_PAGE_ID?fields=access_token&access_token=YOUR_USER_ACCESS_TOKEN (Get specific page token by page ID)

Then you do HTTP POST request (e.g. message=hello) to your page on 3 ways:

  1. https://graph.facebook.com/YOUR_PAGE_ID/feed?access_token=YOUR_PAGE_ACCESS_TOKEN
  2. https://graph.facebook.com/me/feed?access_token=YOUR_PAGE_ACCESS_TOKEN
  3. https://graph.facebook.com/feed?access_token=YOUR_PAGE_ACCESS_TOKEN

Update:

I suggest you to manually granted a User Access Token(e.g. Login/authorization dialog would appear, and user need to manually click to accept APP permission request, you can't programatically web scraping to do this first step, as it's violate TOS of the Facebook platform), then extend it to long-live(Expired 2 months) via https://graph.facebook.com/oauth/access_token?client_id=my_app_id&client_secret=my_app_secret&grant_type=fb_exchange_token&fb_exchange_token=User_Access_Token

And now you have long-live User Access Token, and then call https://graph.facebook.com/me/accounts?access_token=LONG_LIVE_USER_ACCESS_TOKEN to get NEVER expired Page Access Token. You can debug the Page Access Token at https://developers.facebook.com/tools/debug/accesstoken?q=YOUR_PAGE_ACCESS_TOKEN

As you can see, the Expires date is Never:

enter image description here

Documentation:

  1. https://developers.facebook.com/docs/facebook-login/access-tokens/
  2. https://developers.facebook.com/docs/graph-api/reference/app (No such thing post to page as admin)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top