How to post a Facebook fan page as a fan page, not as a user

How can I publish fanpage on the wall as a fanpage, not as a user - using javascript sdk.

RIght is now on Init im getting menage_pages and acquiring the appropriate fanpage id, how can I change the call below?

var target = '/'+params.target+'/feed' FB.api(target, 'post', { message: params.message, link: params.link, picture: params.picture, caption: params.caption, description: params.description, name: params.name } ,function(response) { if (!response || response.error) { $("#error").removeClass('hidden'); } else { $("#success").removeClass('hidden'); } }); 
+4
source share
2 answers

You need the following permissions:

  • publish_stream
  • manage_pages

Now we call the page object to retrieve the access_token page, and then publish this token, for example:

 function postToPage() { var page_id = 'MY_PAGE_ID'; FB.api('/' + page_id, {fields: 'access_token'}, function(resp) { if(resp.access_token) { FB.api('/' + page_id + '/feed', 'post', { message: "I'm a Page!", access_token: resp.access_token } ,function(response) { console.log(response); }); } }); } 

Result:
enter image description here

More on this in the tutorial .

+3
source

All you need are three functions that you need to implement:

Firstly, to set the basic parameters for your application (XXX-APP must be changed using your real application identifier).

Second, log in to Facebook and provide the necessary permissions to post to Facebook.

The third function is intended for publication on Facebook (the XXX page must be changed with the identifier of the page you want to publish)

 FB.init({ appId: 'XXX-APP', status: true, cookie: true, xfbml: true, oauth: true }); access_token = ''; function loginFB(){ FB.login(function(response) { if (response.authResponse) { access_token = FB.getAuthResponse()['accessToken']; console.log('Access Token = '+ access_token); } else { console.log('User cancelled login or did not fully authorize.'); } }, {scope: 'publish_stream,manage_pages'}); } function postToPage() { FB.api('/XXX-page', {fields: 'access_token'}, function(resp) { if(resp.access_token) { FB.api('/' + page_id + '/feed', 'post', { message: "MSG", access_token: resp.access_token } ,function(response) { console.log(response); }); } }); } 
0
source

Source: https://habr.com/ru/post/1379958/


All Articles