We have a custom made CMS that the users have the option of posting to the company's 'fan page' when they post a message. This code uses the FacebookAPI code provided by Facebook to use the Graph API in a C# application (actually a WCF webservice).
We have had various problems posting before (see this bug and this discussion). This had been working for a while, but now returns a 400/Bad Request.
I have tried two different (known working before) api tokens. No code has changed in months on this setup.
I'm wondering how I can figure out why it now will no longer post. Has something changed with the tokens its requesting?
This is the code I am using:
FacebookAPI api = new FacebookAPI(token);
Dictionary<string, string> postArgs = new Dictionary<string, string>();
postArgs["link"] = url;
postArgs["message"] = message;
try
{
JSONObject jsonresult = api.Post("me/links", postArgs);
result = "ok";
}
开发者_Python百科catch (Exception e)
{
result = "Post Failed - " + e.Message.ToString();
}
My exception is stating a 400/Bad Request
update: I also noticed that according to the Authentication Docs, some of the tokens now have an expiration, which mine doesn't seem to have. Could this be an issue? For example, my token is a ~100 char string, with 4 sections seperated by 3 pipes (|). Their examples then have an extra &expires_in=64090.
In order to post links, or statuses now you need a user access_token and permission to links. Be sure the user has given the application doing the link-post has publish_stream perms. Also the message parameter should be ignored on post but i would not pre-fill it just to avoid errors.
You can post a link on the user's behalf by issuing an HTTP POST request to PROFILE_ID/feed with the publish_stream permissions and the following parameters.
http://developers.facebook.com/docs/reference/api/user/#links
javascript sample i use to make posts.
window.feedthis = function(shf,point,clk) {
ptsT=point-shf+clk;
FB.ui({ method: 'feed',
// message: 'Testing Feed',
caption: 'I survived '+shf+' Levels in Another Grid. I earned '+point+' points with '+clk+' clicks.',
name: 'Another Grid',
link: 'http://apps.facebook.com/anothergrid/?ref=link',
//to: '391793380398',
description: 'Another Grid, A color elemination Puzzle game by Shawn E Carter.',
picture: 'https://shawnsspace.com/ShawnsSpace.toon.nocolor..png',
properties: [{ text: 'Play the Game', href: 'http://apps.facebook.com/anothergrid/?ref=achievement'}
//{ text: 'ShawnsSpace', href: 'http://apps.facebook.com/shawnsspace/?ref=anothergrid'}
],
actions: [
{ name: 'Another Grid', link: 'http://apps.facebook.com/anothergrid/'}
]
});
};
精彩评论