【发布时间】:2011-07-10 16:28:40
【问题描述】:
我想通过处理小程序在 facebook 用户的墙上发布一些内容。首先,我通过 Oauth 身份验证获取具有 app_id 和 user_id 的用户的 access_token。 我用了这个code,谢谢豪尔赫
现在我想在用户的墙上发布一个帖子。 我向https://graph.facebook.com/USER_ID/feed 发出http post 请求 使用这些参数 "access_token", "XXX ; "message", "Check ... Processing!"
请求的响应是
executing request: POST https://graph.facebook.com/USER_ID/feed HTTP/1.1
----------------------------------------
HTTP/1.1 403 Forbidden
----------------------------------------
{"error":{"type":"OAuthException","message":"(#200) This API call requires a valid app_id."}}
这是什么意思? 我输入了一个有效的 app_id...否则我没有获得 access_token?
问候, 彼得
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
void setup()
{
String url = "https://graph.facebook.com/USER_ID/feed";
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost( url );
HttpParams postParams = new BasicHttpParams();
postParams.setParameter( "access_token", "XXX" );
postParams.setParameter( "message", "Check ... Processing!" );
httpPost.setParams( postParams );
println( "executing request: " + httpPost.getRequestLine() );
HttpResponse response = httpClient.execute( httpPost );
HttpEntity entity = response.getEntity();
println("----------------------------------------");
println( response.getStatusLine() );
println("----------------------------------------");
if( entity != null ) entity.writeTo( System.out );
if( entity != null ) entity.consumeContent();
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpClient.getConnectionManager().shutdown();
} catch( Exception e ) { e.printStackTrace(); }
exit();
}
【问题讨论】:
-
你获得
publish_stream权限了吗?如果您不需要access_token! -
我做了这个请求:http://www.facebook.com/login.php?api_key=YOUR_API_KEY&connect_display=popup&v=1.0&next=facebook.com/connect/login_success.html&cancel_url=http: //www.facebook.com/connect/ login_failure.html&fbconnect=true&return_session=true&req_perms=read_stream,publish_stream,offline_access ,但是http post请求不起作用。
-
抱歉 http:// 之间有空格,否则链接将无法正确显示。
-
我遇到了类似的问题,问题出在 HttpParams 上。解决方案是使用 NameValuePair。就像这里:stackoverflow.com/questions/4424425/…
标签: facebook http post oauth processing