How can I post to a company Facebook page from an offline app (using the C# SDK)? -
i'm trying use facebook c# sdk publish posts wall of company page. need batch job, not web app particular user interacting with. have facebook application set under own facebook id, , have granted publish_stream, share_item, offline_access, , manage_pages permissions under account. (i can verify these permissions have been granted app under facebook settings page.) , company page i'm trying post page created myself, should have full access it.
i authenticating facebook app id , secret application, getting access token, putting message post, trying post it. following exception:
facebook.facebookoauthexception unhandled user code message=(oauthexception) (#200) user hasn't authorized application perform action
i've tried few variations on theme, can't seem figure out i'm doing wrong. here's bit of code:
var client = new facebookclient("app id", "secret"); _log.debugformat("access token={0}", client.accesstoken); dynamic parameters = new expandoobject(); parameters.message = "testing 123"; /* fill in other parameters */ dynamic result = client.post(fanpageid+"/feed", parameters); /* here's exception */
i have seen references pulling page-specific access token out of data returned /me/accounts, can't figure out how offline app that's authenticating facebook app, rather facebook user.
update: i've gotten part of way there using bit of code connect facebook:
var client = new facebookclient("non-expiring oauth token");
...where "non-expiring oauth token" 1 shown in developer app on facebook app in question.
this still posting under own id though, need go step of figuring out how post appear come page itself.
i've figured out now, i'm going answer own question. method allowed me post fan page, under 'name' of fan page, without user intervention, using facebook.dll (not requiring facebook.web.dll).
// init non-expiring access token app can manage fan page var client = new facebookclient(fbappoatoken); // accounts, using facebook id user has admin rights fan pge dynamic accts = client.get(string.format("/{0}/accounts", fbappadminuser)); // find access token fan page string page_access_token = null; foreach (var acct in accts.data) { if (acct.id == fbfanpageid) { page_access_token = acct.access_token; break; } } // fill in parameters message post dynamic parameters = new expandoobject(); parameters.message = "testing 123"; // , include access token retrieved above parameters.access_token = page_access_token; dynamic result = client.post(fbfanpageid + "/feed", parameters);
if has quicker or easier way of doing this, please let me know. stumbled through until put enough puzzle pieces work. thanks.
Comments
Post a Comment