1

I'm using the following code (which has been posted somewhere on Stackoverflow) to post on Facebook Page's wall.

It works fine, but it opens Facebook Login window if I'm not logged in. Is it possible to execute the code on behalf of administrator account of particular Facebook Page?

    protected void Page_Load(object sender, EventArgs e)
    {
        string app_id = "123410186463705";
        string app_secret = "1234ecd9bea862197372de656eb3d7b";

        // using Facebook SDK for .NET
        var fb = new FacebookClient();
        dynamic result = fb.Get( "oauth/access_token", new
        {
          client_id = app_id,
          client_secret = app_secret,
          grant_type = "client_credentials",
          scope = "manage_pages,offline_access,publish_stream",
          redirect_uri = Request.Url.AbsoluteUri
        } );

        var app_token = result.access_token;

        var client = new FacebookClient(app_token);

        dynamic parameters = new ExpandoObject();
        parameters.message = "Check out this funny article";
        parameters.link = "http://www.natiska.com/article.html";
        parameters.picture = "http://www.natiska.com/dav.png";
        parameters.name = "Article Title";
        parameters.caption = "Caption for the link";

        //446533181408238 is my fan page
        client.Post("/446533181408238/feed", parameters);
    }
Ivan Studenikin
  • 1,362
  • 4
  • 17
  • 30

1 Answers1

3

Yes, it's possible. You need to use a page access token.

Generating a Page Access Token.

Once you receive a page access token, you can store it as it never expires(if generated through long-lived user token/server side user token). Finally initialize your FacebookClient with that token.

A C# specific tutorial is here. The article really old and using the deprecated offline_access permission, but atleast you will get the logic right.

ThePCWizard
  • 3,338
  • 2
  • 21
  • 32