15

I have read the fb docs and written code to publish a message to a facebook "page", however I am getting an error that I don't expect to see:

(#200) The user hasn't authorized the application to perform this action

Here's what I've done:

  • I set up a facebook application, which provides my APP_ID and APP_SECRET.
  • I set up a test facebook "page". Let us refer to its fb id as PAGE_ID.
  • Used OAuth to get a USER_ACCESS_TOKEN with scope "publish_actions,manage_pages" for the user. I accepted the permissions requested by my app when redirected to the facebook auth page.
  • I did a GET on https://graph.facebook.com/me/accounts using the USER_ACCESS_TOKEN, and I get back a list of pages I administrate, including the one I want to post to.

This block of data for my page looks like:

{
  "data": [
    {
      "category": "Community", 
      "name": "My Generic Test Page", 
      "access_token": PAGE_ACCESS_TOKEN, 
      "id": PAGE_ID, 
      "perms": [
        "ADMINISTER", 
        "EDIT_PROFILE", 
        "CREATE_CONTENT", 
        "MODERATE_CONTENT", 
        "CREATE_ADS", 
        "BASIC_ADMIN"
      ]
    }, 
    ....
  ]
}

Then I use the PAGE_ACCESS_TOKEN to post a message to the page:

  • I did a POST on https://graph.facebook.com/PAGE_ID/feed with a field message equal to This is a test post.

Facebook returns:

{
  "error": {
    "message": "(#200) The user hasn't authorized the application to perform this action", 
    "type": "OAuthException", 
    "code": 200
  }
}

Using the token debugger, I can confirm that my PAGE_ACCESS_TOKEN is valid, and has scopes: manage_pages and publish_actions.

Where am I missing authorizing the application? Do I need additional scopes? Did I miss clicking something on the facebook authorization screen? Is there a setting on the app I am missing? After days of debugging this, I must be blind to the problem. :-|

broc.seib
  • 21,643
  • 8
  • 63
  • 62
  • can you please share your code i am getting exact same error ? Or can you please have a look at this question http://stackoverflow.com/questions/40434951/unable-to-post-to-facebook-page-javascript#40434951 – Mairaj Ahmad Nov 05 '16 at 06:34

4 Answers4

27

You should add permission called status_update, for example

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=status_update&from_login=1&m_sess=1&rcount=1

enter image description here

and i'm able post to page i liked with the access token i get just now: enter image description here

If you want to post as the admin of the page, you're require both manage_pages and status_update permissions, for example

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&from_login=1&m_sess=1&rcount=1

enter image description here

Cheers

Community
  • 1
  • 1
林果皞
  • 7,539
  • 3
  • 55
  • 70
  • 2
    Yes! "status_update" was the permission I was missing. Thank you. Now why can't I find any mention of "status_update" among all the facebook docs about permissions? https://developers.facebook.com/docs/concepts/login/permissions-login-dialog/ – broc.seib Apr 11 '13 at 18:40
  • I filed an issue with FB about the missing docs (or otherwise a bug). https://developers.facebook.com/bugs/289826861149962 – broc.seib Apr 11 '13 at 19:12
  • 3
    @broc.seib If you visit https://developers.facebook.com/tools/explorer, click the "Get access token" button, then you can found "status_update" under "Extended Permissions" tab. The official documentation is not always complete and up to date. – 林果皞 Apr 15 '13 at 06:26
  • @林果皞 As of today with v2.2, there is no `status_update` permission available to me in the Extended Permissions tab. – ian Mar 19 '15 at 05:19
  • 3
    @iain You now need the publish_pages permission for 2.3. https://developers.facebook.com/docs/apps/changelog – sbaar Mar 28 '15 at 07:20
  • 1
    Downvoting because this answer isn't an option that I can see in Facebook Graph API 4.x – AndrewSmiley Jun 24 '15 at 00:47
  • 3
    @AndrewSmiley Are u kidding to downvote ? The version of Graph API is only v1.0 when i posted the answer. Do you expect the answer is still valid for Graph API v100 ? – 林果皞 Jun 24 '15 at 08:26
  • @林果皞 can you please share the code for javascript i am getting exact same error or can you please have a look at this question.http://stackoverflow.com/questions/40434951/unable-to-post-to-facebook-page-javascript#40434951 – Mairaj Ahmad Nov 05 '16 at 06:35
3

status_update is not used anymore. To publish on pages, I had to use both manage_pages and publish_pages.

broc.seib
  • 21,643
  • 8
  • 63
  • 62
syldor
  • 1,176
  • 1
  • 9
  • 14
2

Well, this seems to be a common mistake that most of us make while trying to do an activity in social netwroks. Before trying to put up an open graph action,You need to set the permissions in your initial authorization request . By default you only gain 'read-only' access to their basic information. Settintg up permisson at teh time of authetication is a must for Facebook and LinkedIn APIs..

See the public_actions section in Facebook open graph permissions here and make relevant changes in the authorization code , and get your issue solved.

DD_
  • 7,230
  • 11
  • 38
  • 59
  • 1
    In my third step, I had successfully requested (and been granted) permissions "publish_actions" and "manage_pages". What other permissions are required to post a message to a facebook page? – broc.seib Apr 07 '13 at 15:29
  • I'd take a working code sample in about any language. I happen to be using java (using Scribe and RestFB). I've also distilled the problem down enough that I can reproduce it using just the GraphExplorer poking the raw HTTP API. So it would fit that this is a matter of getting the right permissions lined up. – broc.seib Apr 07 '13 at 15:34
  • I *did* set permissions in my initial request. I'll ask again: *Which* permissions are needed besides "publish_actions" and "manage_pages"? – broc.seib Apr 10 '13 at 14:31
  • If you have already set the permissions, you get this error because you are not correctly switching the request to post, see [this answer](http://stackoverflow.com/a/4522249/1756131) – DD_ Apr 11 '13 at 04:34
1

I found the best way to get a valid token and check permissions was via the Graph API Explorer BUT while Facebook's documentation is extensive it is not always the easiest to follow.

In the explorer you have to look at both:

  1. The Application Currently at the top and quite subtle, I missed this for ages.
  2. Get Token Dropdown What you click to get a Token, when you click the arrow you can choose pages and other items you have access to for selecting a token for.
The Coder
  • 4,981
  • 2
  • 29
  • 36