2

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()
{
  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();
}
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
iam_peter
  • 3,205
  • 1
  • 19
  • 31
  • Have you acquired the `publish_stream` permission? if you did no need for the `access_token`! – ifaour Mar 08 '11 at 08:48
  • i did this request: http: //www.facebook.com/login.php?api_key=YOUR_API_KEY&connect_display=popup&v=1.0&next=http://www.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 , but the http post request is not working. – iam_peter Mar 08 '11 at 09:20
  • sorry for the spaces between http: //, but otherwise the links wouldn't show up correct. – iam_peter Mar 08 '11 at 09:23
  • I had a similar issue and the problem was with HttpParams. The solution was to use NameValuePair. Just like here: http://stackoverflow.com/questions/4424425/cant-get-httpparams-working-with-postrequest – Leandro Alsberg Sep 17 '13 at 20:43

1 Answers1

0

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'

Simon Cross
  • 13,315
  • 3
  • 32
  • 26