Question

I have created a facebook page and a facebook application for my website and now I need to post messages onto the facebook page with help of facebook SDK .NET.

This is what I got so far :

public static bool UploadPost(string message)
    {
        dynamic result;

        //https://developers.facebook.com/tools/explorer/
        //https://developers.facebook.com/tools/access_token/
        FacebookClient client = new FacebookClient("secret access token");


        result = client.Get("oauth/access_token", new
            {
                client_id = "[Client ID number]",
                client_secret = "[Client sercret",
                grant_type = "client_credentials",
            });

        result = client.Post("[facebook app Id]/feed", new { message = "Test Message from app" });
        //result.id;
        result = client.Get("[facebook app Id]");

        return false;
    }

When running this I get : Additional information: (OAuthException - #200) (#200) The user hasn't authorized the application to perform this action on client.Post. If I remove the client.Post row every thing works good, the correct data is fetched.

I have tried follow some helps on facebook SDK .NET website but it is still not working.

The main problem now is that I get permission exception. I was hoping that my facebook app hade enouth permissions to publish post from my website to the facebook page.

Was it helpful?

Solution 4

By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?

Im surprised that this simple task was so hard to get running and that there was vary little help to get.

OTHER TIPS

Here is a step wise tutorial to register your application with facebook and get an app Id for your application.

Then for permissions ::

    private const string ExtendedPermissions = "user_about_me,read_stream,publish_stream";

This is a string of permissions. Pass it on further for getting correct permissions to post messages on page. Post using your standard code for posting no FB pages. Cheers. Hope it helps.

Are you trying to post to [facebook app id]?

I would recomend to post to "me/feed" and test if that works.

Also, to post to Facebook you have to have the publish_stream permission

private async Task Authenticate()
{
    string message = String.Empty;
    try
    {
        session = await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream,publish_actions");
        App.AccessToken = session.AccessToken;
        App.FacebookId = session.FacebookId;

        Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Pages/LandingPage.xaml", UriKind.Relative)));
    }
    catch (InvalidOperationException e)
    {
        message = "Login failed! Exception details: " + e.Message;
        MessageBox.Show(message);
    }
}

Should work :)

The following should work.

var fb = new FacebookClient("access_token");

fb.PostCompleted += (o, e) => {
    if(e.Error == null) {
        var result = (IDictionary<string, object>)e.GetResultData();
        var newPostId = (string)result.id;
    }
};

var parameters = new Dictionary<string, object>();
parameters["message"] = "My first wall post using Facebook SDK for .NET";
fb.PostAsync("me/feed", parameters);

This was taken directly from the documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top