I want to thank you for your post, it was really useful. For me, it was still hosted on my Facebook page as ME (not as a page). I think this is exactly how I get the token. Although, the foreach loop did not work for me. So, I did this:
public void postFacebook(object sender, EventArgs e) { //You will get your "myAccessToken" at this adress: //https://www.facebook.com/dialog/oauth?client_id=<YOUR_APP_ID>&redirect_uri=<THE_PAGE_YOU_WILL_RECEIVE_YOUR_TOKEN_AT>&scope=offline_access,manage_pages,publish_stream&response_type=token string myAccessToken = "<IN_THE_RETURNED_URL_BELOW>"; string myPageId = "<YOUR_FAN_PAGE_ID>"; Dictionary<string,string> fbParams = new Dictionary<string,string>(); fbParams["message"] = "Testing 1 2 test"; fbParams["caption"] = string.Empty; fbParams["description"] = string.Empty; fbParams["req_perms"] = "publish_stream"; fbParams["scope"] = "publish_stream"; //Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users Facebook.FacebookAPI fbClient = new Facebook.FacebookAPI(myAccessToken); //Get the listing of accounts associated with the user var fbAccounts = fbClient.Get("/me/accounts"); //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID) foreach (var account in fbAccounts.Dictionary["data"].Array) { if (account.Dictionary["id"].String == myPageId) { //When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out. fbParams["access_token"] = account.Dictionary["access_token"].String; //Update the Access token (to post as the page). If you don't it will post as YOUR personal name. fbClient.AccessToken = fbParams["access_token"]; break; } } //Then pass your destination ID and target along with FB Post info. You're Done. dynamic publishedResponse = fbClient.Post("/" + myPageId + "/feed", fbParams); }
By the way, you will need this sdk: SDK
source share