http post facebook graph api processing
i want to post something on the wall of a facebook user via a processing applet. first i get the access_token for the user with the app_id and user_id through the Oauth authentication. i used this code, thanks Jorge
now i want to publish a post on the wall of the user. i make a http post request to https://graph.facebook.com/USER_ID/feed with these arguments "access_token", "XXX ; "message", "Check ... Processing!"
the response of the request is
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."}}
what does that mean? i have entered a valid app_id...otherwise i didn't get the access_token?
regards, peter
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()
{
Stri开发者_开发技巧ng 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();
}
You need to include the User ID in the URL of your request, not the literally 'USER_ID'.
so you could either do:
String url = "https://graph.facebook.com/"+user_id+"/feed";
or, use the shortcut, litereally:
String url = "https://graph.facebook.com/me/feed";
where Facebook looks at the user ID in the access token in leiu of 'me'
精彩评论