开发者

Facebook C# SDK - Post to wall

I'm developing an asp.net MVC 3 Facebook app and I am trying to post a message to my wall. Here is my code:

FacebookWebClient client = new FacebookWebClient();

// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com;
postparameters["description"] = "This is a description";

var result = client.Post("/me/feed", postparameters);

I can get the access token using client.AccessToken, so I'm assuming I don't have to set it anywhere. This code produces no errors and for the result I get an ID. However, when I bring up my Facebook, I see nothing on my wall nor in my news feed. I'm not sure what I'm missing. I've looked at related questions here at StackOverflow, but I see no reports/questions similar to mine. I've also tried changing the code based on what I've seen in other posts, but to no avail. I also checked my Facebook account settings and I see my application listed with permission to post to my wall. I also tried posting a message to my wall via the Graph API explorer and I'm getting the same result. I get an ID in return, but when I check my Facebook account I see nothing. At been at this for a couple of days. Any help would be greatly appreciated.

Thanks in advance.

[EDIT] I wonder if something is wrong with my app generated access_token. Using this access_token, as I mentioned in my post, I get the same result using the Graph API explorer. An ID is returned, but no message on my wall. However, if I give the Graph API explorer permission to post to my wall and use its own generated access_token, I can successfully post a message using the explorer. Here's the FB login button code:

<div>
    <h1>Login using Facebook</h1>
    <p><fb:login-button perms开发者_运维百科="user_location, publish_stream, email"></fb:login-button></p>
</div>


Basically you need to add an additional parameter into your post parameters.

args["access_token"] = account.access_token;

this is the token of the specific page.

I wont repeat the code, follow here for example: Post On Facebook Page As Page Not As Admin User Using Facebook C# SDK

(second answer)


Did you request right App permissions to Facebook in your action method?

Try: [CanvasAuthorize(Permissions = "user_location, publish_stream, email")]


Did you append the access_token to the URL? See example here. It's also documented here (see Using the Access Token).

/me/feed?access_token=<access_token>


with one small change, your code works fine for me. you have to pass the users auth token into the constructor like this...

var client = new FacebookClient(accessToken);

// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com;
postparameters["description"] = "This is a description";

var result = client.Post("/me/feed", postparameters);

this method works for me, although i am not sure which facebook sdk you are using. i'm using http://facebooksdk.net/ its quite good so if you're not using it i would recommend it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜