Posting on Facebook page as page not as Admin user using Facebook C # SDK

I am developing a C # application that manages a Facebook fan page that uses the Facebook C # SDK. I ran into two problems with posting on the wall, and the other with creating events on the fans page.

Is it possible to post a message on the fan page wall as a fan page rather than an admin?

Can I programmatically create an event on a fan page (not as an administrator, but as a fan page) using the Facebook C # SDK?

I looked through some other lessons from other SDKs such as the PHP PHP SDK. The PHP SDK allows you to create events as a fan page, but in the case of the C # SDK, the creation event does not produce any results.

+4
source share
4 answers

To post a message, you need to grant manages_pages permission and get the access token from the accounts for the fan page using the results "/ me / accounts".

Here is what I use to post the message itself on the fan page:

var dicParams = new Dictionary<string, object>(); dicParams["message"] = stSmContentTitle; dicParams["caption"] = string.Empty; dicParams["description"] = string.Empty; dicParams["name"] = smContent.CmeUrl; dicParams["req_perms"] = "publish_stream"; dicParams["scope"] = "publish_stream"; // Get the access token of the posting user if we need to if (destinationID != this.FacebookAccount.UserAccountId) { dicParams["access_token"] = this.getPostingUserAuthToken(destinationID); } publishResponse = this.FacebookConnection.Post("/" + destinationID + "/feed", dicParams); 
+1
source

Well, I just came across this one and the same. For my purposes, I authorize the application to publish to the FB fan page as a fan page. Thus, I can have several users who have access to the application, but not access to the fan page, wiring as a fan page. It works for my requirements.

Anyway, here is how I did it using the C # Facebook SDK Beta V5.0.9. The first step is to make sure that the user account with which you are trying to send a message has the ability to publish on the fan page and has the right to do this from the application.

Most of them are similar to the VorTechS post, with a bit more explanation on it.

 Dictionary<string,string> fbParams = new Dictionary<string,string>(); fbParams["message"] = Title; 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 FacebookWebClient fbClient = new FacebookWebClient(<YOUR_ACCOUNT_ACCESS_TOKEN>); //Get the listing of accounts associated with the user dynamic fbAccounts = fbClient.Get("/me/accounts"); //Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID) foreach (dynamic account in fbAccounts.data) { if (account.id == <DESTINATION_ID_OF_YOUR_FAN_PAGE>) { //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.access_token; break; } } //Then pass your destination ID and target along with FB Post info. You're Done. dynamic publishedResponse = fbClient.Post("/" + <DESTINATION_ID_OF_YOUR_FAN_PAGE> + "/feed", fbParams); 
+7
source

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

+1
source

in MVC4 and C # SDK, this got my goal

  [FacebookAuthorize("publish_stream")] public ActionResult PostNotification(FacebookContext context) { var dicParams = new Dictionary<string, object>(); dicParams["message"] = "đang tập code cho facebook ~@ @"; dicParams["caption"] = "bbbbb"; dicParams["description"] = "cccccc"; dicParams["name"] = "http://www.facebook.com"; dicParams["req_perms"] = "publish_stream"; dicParams["scope"] = "publish_stream"; string destinationID = context.UserId; context.Client.Post("/" + destinationID + "/feed", dicParams); return RedirectToAction("Index"); } 
+1
source

Source: https://habr.com/ru/post/1342799/


All Articles