prabirshrestha / FacebookSharp

Facebook Graph API for .Net
Other
30 stars 15 forks source link

post to a facebook page as page (not as user) #8

Closed ceocoder closed 14 years ago

ceocoder commented 14 years ago

Is that possible, and if so how, thanks.

prabirshrestha commented 14 years ago

Yes, it is possible, but a bit tricky.

It depends on the access token you are using. There are two ways to do it.

  1. Using the user's access token. if the user is the admin of the page, it will automatically post as the page rather than the user, else will post as the user. var fb=new Facebook("admin_user_access_token"); fb.PostToWall("message",null,page_id);
  2. using the page access token. this access token is diffrent from the user's access token. to get the page access token, get the list of the pages first

var fb=new Facebook("user_access_token"); var pages = fb.GetMyPages();

foreach(var d in result.Data){ /* access your page access token using d.AccessToken */ }

d.AccessToken is the page AccessToken

u can then use that access token to post to the wall

var fb=new Facebook(d.AccessToken); fb.PostToWall("message",null);

hope this helps. in case you have any problems, please feel free to ask.

All the above methods uses the new graph api, I have also added some methods to use the old rest api.

inorder to check if the user is the admin of the page or not, u can use the old rest api to do it. var fb=new Facebook("user_access_token"); bool result = fb.AmIAdminOfPage("pageId"); or bool result = fb.IsAdminOfPage("user_id","pageid");

note: I'm using Facebook.Core and Facebook.Extensions library

ceocoder commented 14 years ago

thanks prabir,

first option did not work, it showed up as a post from my user acct, but second option did, thanks again.

prabirshrestha commented 14 years ago

funny, coz i use (and prefer) the first option and it works. are you sure u specified the 3rd parameter, page_id. (note: the user has to be the admin of the page, otherwise it will post as normal user.)

fb.PostToWall("message",null,page_id);

prabirshrestha commented 14 years ago

closed

prabirshrestha commented 14 years ago

i tested it and seems like facebook recently just changed it. u have to use the page access token to post as page.