Friday, 02 August 2013 23:15

how to post to facebook page wall by Graph Api

Written by 
Rate this item
(0 votes)
Facebook Graph Api enables to post to any public page/profile wall
on behalf of any user.In the following codes i show how using
fb javascript sdk-
before running you have initialize facebook javascript sdk by this
way -

In the following codes the user is made login to facebook by
FB.login call.After user grants permission, a temporary access
token "token" is retrieved, which is used for Graph api call
FB.api.Before that you have to get the page/profile id and place
as a parameter in the FB.api call below -

FB.login(function(response) {
if (response.status=='connected') {
if (response.authResponse.accessToken)
var token = response.authResponse.accessToken;
FB.api('/'+Page/profile_id_here +'/feed?access_token='+token+'&message=test_message', 'POST', function(response){
if (!response || response.error) {
} else {
alert('posted successfully');
} else {
// user is logged in, but did not grant any permissions
alert('Error: You can create an access token only for your own profiles and pages.');
} else {
// user is not logged in
alert('Error: To Post you have to generate an access token.');
}, {scope:'publish_stream' });

Hope that helps.Don't forget to like and share.
Read 3269 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.