Mikael
Mikael

Reputation: 21

How to post as application to facebook wall, using Facebook C# SDK?

This is my very first try using this SDK, so be gentle with me. I did this:

var fbWebContext = FacebookWebContext.Current;
if (fbWebContext.IsAuthorized())
{
    // post as application
    var fb = new FacebookOAuthClient { AppId = "205378862824897", AppSecret = "4deb72e26c22415fe00e44028b401114" };
    dynamic result = fb.GetApplicationAccessToken();
    var appAccessToken = result.access_token;

    Dictionary<string, object> parameters = new Dictionary<string, object>()
                                                {
                                                    {"description", "Testbeskrivning"},
                                                    {"link", "http://zitac.se"},
                                                    {"name", "Testtitel" }
                                                };
    var fbApp = new FacebookWebClient(appAccessToken);
    result = fbApp.Post(FB_ID_FANPAGE + "/feed", parameters);

    lblMessage.Text = result;
}

And got his: (OAuthException) (#200) The user hasn't authorized the application to perform this act.

Is there some settings needed on the fan page?

This is using ASP.NEt 4.0 and SDK 5.0.7.

Upvotes: 1

Views: 2950

Answers (2)

DevTheo
DevTheo

Reputation: 921

Andy has it mostly, BUT there is something else here that I realized. It sounds like you want to post AS THE APP to the user's wall. If you are just wanting something to show up on the user's news feed then you need the user to like your app. And then when you post to the app's wall, it should show up on the user's feed (actually all user's news feed).

If you want a direct to the user's wall, then you need to post to "{facebook userid}\feed". Mind you Facebook may or may not allow this (I have forgotten whether they do or not at this moment).

From what I can tell what you have done so far should work. The problem you are having is that you are posting to an unknown fan page (Is the app authorized on that fan page?)

Upvotes: 0

Andy Sinclair
Andy Sinclair

Reputation: 2303

The error "The user hasn't authorized the application.." sounds like the Facebook user does not have the necessary permissions, check here for details.

They would need as a minimum to have authorized 'publish_stream'.

Check the permissions you are asking for in the JavaScript on your page; the Facebook Javascript reference explains this in detail.

Hope this helps.

Upvotes: 2

Related Questions