facebook publish to wall as page
I am developing a facebook application.
In my application I'd like to give page administrators the ability to publish to their page's wall, not as a user,开发者_高级运维 but rather as they page itself.
Can this be done? If so how?
Thank you.
Apperently this possible when prompting user with the "manage_pages" permission. Then it is possible to query the page's access token, and perform the operation in the page's name. You can check this documentation down here: http://developers.facebook.com/docs/authentication/
And here's a small code sample, of how it might look using the facebook c# sdk:
dynamic pagesInfo = FacebookApp.Api("/me/accounts");
JavaScriptSerializer serializer = new JavaScriptSerializer();
string pageAccessToken = null;
foreach(IDictionary<string,object> page in serializer.DeserializeObject(pagesInfo.data.ToString()))
{
long pageId = long.Parse(page["id"].ToString());
if (pageId == localBusiness.FanPageId)
{
pageAccessToken = page["access_token"].ToString();
}
}
if (pageAccessToken == null)
return;
var pageFbApp = new FacebookApp(pageAccessToken);
// post as application
Dictionary<string, object> parameters = new Dictionary<string, object>()
{
{"from",
new Dictionary<string,object>()
{
{"id" , localBusiness.FanPageId},
{"name" , localBusiness.Name}
}},
{"description", description},
{"link", pageUrl },
{"name", name },
{"picture" , imageUrl }
};
dynamic result = pageFbApp.Post(localBusiness.FanPageId + "/feed", parameters);
精彩评论