我想通过处理applet在facebook用户的墙上发布一些东西。首先,我通过Oauth身份验证为app_id和user_id的用户获取access_token。我用这个code,谢谢Jorge
现在我想在用户的墙上发布帖子。我使用这些参数“access_token”,“XXX;”消息“,”检查......处理!“向https://graph.facebook.com/USER_ID/feed发送http发布请求!”
请求的响应是
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();
}
您需要在请求的网址中包含用户ID,而不是字面上的“USER_ID”。
所以你可以这样做:
String url = "https://graph.facebook.com/"+user_id+"/feed";
或者,使用快捷方式,字面意思:
String url = "https://graph.facebook.com/me/feed";
Facebook在访问令牌中查看用户ID而不是“我”