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); }); } }); }
raBne source share