我试图让已经链接其Facebook帐户的用户能够通过一个按钮按下detailed in their docs来发布到他们的墙上。具体来说,我不想使用Facebook for Android library中提供的.dialog方法,因为我希望发布过程尽可能无缝。从Android应用程序发布到Facebook订阅源
特定呼叫看起来像这样在HTTP客户端模拟器:
HTTP POST
https://graph.facebook.com/me/feed
内容类型:应用/ X WWW的窗体-urlencoded
的access_token = ... &链接= http://mylink.com/id/1326&name=What做您认为? &描述=链接
此调用的说明成功地运行在HTTP客户端在OS X
我最初试图使用Facebook的Android库与“stream.publish”行动.dialog功能,但是这会导致不想要的对话框出现。
接下来,我尝试使用Facebook的Android的.request函数与“POST”参数,但此函数假定正文是一个字节数组,并在库中的多个位置失败。
现在,我正在尝试使用Android中包含的Apache HTTP堆栈。 具体来说,我的代码看起来是这样的:
String url = "https://graph.facebook.com/me/feed";
ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>(4);
pairs.add(new BasicNameValuePair("access_token", App.facebook.getAccessToken()));
pairs.add(new BasicNameValuePair("link", "http://mylink.com/id/"+id));
pairs.add(new BasicNameValuePair("name", question));
pairs.add(new BasicNameValuePair("description", description));
InputStream inputStream = null;
HttpResponse response = null;
HttpClient client = null;
try {
final HttpPost post = new HttpPost(url);
final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs);
post.setEntity(entity);
client = new DefaultHttpClient();
response = client.execute(post);
} catch (IOException e) {
// code to handle exceptions
}
// close streams, etc.
的问题是,从Facebook的反应是一致的以下内容:
{"error":{"type":"OAuthException","message":"Invalid OAuth access token."}}
我知道OAuth访问令牌是不是无效的。当我将相同的OAuth访问令牌粘贴到HTTP客户端时,它就像冠军一样。看起来创建HttpPost对象的参数是以某种方式篡改复杂的OAuth访问令牌。有没有人有如何进行的建议?
你在Facebook的 – 2011-09-26 10:03:05