Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 315
Mokhlisse Badre Avatar asked Dec 04 '22 05:12

Mokhlisse Badre


2 Answers

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.

like image 198
DMCS Avatar answered Dec 14 '22 22:12

DMCS


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());
like image 26
W00di Avatar answered Dec 15 '22 00:12

W00di