Mokhlisse Badre
Mokhlisse Badre

Reputation: 43

The user hasn't authorized the application to perform this action

I am developing a simple java program to post automatically (articles) to my facebook fun page. I have created an app and have got an access_token using url : https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=CLIENR_SECRET. I use this java code to post to fun page wall :

String url = "https://graph.facebook.com/" + PAGE_ID + "/feed"
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("access_token", accessToken));
nvps.add(new BasicNameValuePair("message", item.getTitle()));
HttpClient client = new DefaultHttpClient(params);
HttpPost httpost = new HttpPost(url);
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = client.execute(httpost);
HttpEntity entity = response.getEntity();

I got this error:

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

How can I give my app authorization to post to my fun page ? thanks in advance

following recommendation of

Upvotes: 4

Views: 25288

Answers (4)

havasi
havasi

Reputation: 567

Facebook has changed the publish_stream permission to publish_actions. So you need to apply both publish_actions and manage_pages permissions.

Upvotes: 0

Sabya
Sabya

Reputation: 978

simple, u just need to ask permissions..that's it..

String[] permissions = { "offline_access", "publish_stream", "user_photos", "publish_checkins","photo_upload" };
mFacebook.authorize(MainActivity.this, permissions,
            new LoginDialogListener());

Upvotes: 2

Juicy Scripter
Juicy Scripter

Reputation: 25918

You're using application access_token while you should use access_token for user or page.

  • User's access_token is present within signed_request (in cookie, or passed to application canvas).
  • Page access_token available in accounts connection of user once user granted manage_pages permission to your app.

Update:
To post as Administrator you'll need the user's access_token.
To post as Page you'll need page access_token

Upvotes: 0

DMCS
DMCS

Reputation: 31870

Wow, I see this same question asked at least once a day.

You will want to ask for manage_pages and publish_stream. Once the admin of the page authenticates, query me/accounts and grab the page's access token from that list. Using that page's access token, then you can post to me/feed.

Upvotes: 15

Related Questions