0

I'm trying to publish pictures on Facebook events under Facebook pages I own as that owning page using python. I am attempting to do so as the admin of an app.

The best understanding I have of the process (obviously not good enough) is that it is a two step process: 1) get page_token for target page using user_token (have a long-lived one) 2) use page_token to publish content.

Something like this:

def getFbGraph(accessToken=user_token):
return facebook.GraphAPI(access_token=accessToken)

page_token = getFbGraph().get_object(pageID, fields=['access_token'])

getFbGraph(page_token).put_object(parent_object=eventID, connection_name='photos', message='This is my caption', url=imgUrl)

That gets me the following error message:

facebook.GraphAPIError: Invalid OAuth access token

If instead I try to put the photo as a user (i.e. without the pageToken) I get the following message:

facebook.GraphAPIError: (#200) Requires extended permission: publish_actions

Is there no way for the admin of a page and an app to programmatically post allowed content? I don't need other FB users to be doing that (hence need to go through the publish_actions permissions) and I own all the pages I'm posting to.

Many thanks in advance for your comments.

Panos
  • 163
  • 2
  • 12
  • _“Is there no way for the admin of a page and an app to programmatically post allowed content?”_ – of course there is - using a page token. That you did not manage to pass a page access token the correct way, does not change the fact that this is how it works. – CBroe Jun 28 '17 at 10:43
  • @CBroe - given I share how I attempted to use a page token and failed, that is a supremely unhelpful comment. Can you help suggest the right way to do it? Otherwise, as far as I'm concerned, you can keep those kinds of comments to yourself. – Panos Jun 29 '17 at 15:27
  • It said, your token was invalid. So have you checked what `page_token` actually contains ...? – CBroe Jun 29 '17 at 16:26
  • @CBroe - yes, page_token contains a seemingly valid access token of similar format to the user_token I'm using to retrieve it in page_token = getFbGraph().get_object(pageID, fields=['access_token']). Then when I use that page_token to put a photo on the event I get the Invalid OAuth message. – Panos Jul 19 '17 at 14:41
  • Debug the token here to see if it is actually valid and contains the right permissions: https://developers.facebook.com/tools/debug/accesstoken/ – CBroe Jul 19 '17 at 16:18
  • Same error message, no further info or way to dig deeper. I suspect - on further investigation - that what I need to be able to publish on the event of my page (not the page feed) is publish_actions permission. Which will require Facebook review. Which looks pretty complicated. – Panos Jul 25 '17 at 11:13
  • If you are only going to use this app yourself, and it is not meant for the general public, then you don’t need review. https://developers.facebook.com/docs/apps/faq#faq_180362122361921 – CBroe Jul 25 '17 at 11:17
  • You're right. I wasn't able to figure it out till I stumbled on this other thread: https://stackoverflow.com/questions/8231877/facebook-access-token-for-pages. Not sure what page token my code above returned. With the token I got from Graph API Explorer (link in thread attached above) I got it to work. Thank you for your help - it steered me in the right direction. – Panos Jul 25 '17 at 11:36

0 Answers0