Facebook app request in java not working
Posted
by
Arpit Solanki
on Stack Overflow
See other posts from Stack Overflow
or by Arpit Solanki
Published on 2012-09-23T03:35:08Z
Indexed on
2012/09/23
3:37 UTC
Read the original article
Hit count: 282
I am trying to send a facebook app request to a user through the code below.But it gives an IO Exception and HTTP status code 400 in running.I dont see a any app request being sent to a user on running this.
StringBuffer buffer = new StringBuffer();
buffer.append("access_token").append('=').append(this.app_access_token);
buffer.append('&').append("message=").append("sent an app request!");
String content = buffer.toString();
try{
URLConnection connection = new URL("https://graph.facebook.com/me/apprequests").openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length",Integer.toString(content.length()));
DataOutputStream outs = new DataOutputStream(connection.getOutputStream());
outs.writeBytes(content);
outs.flush();
outs.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
catch(Exception e){
System.out.println(e);
}
© Stack Overflow or respective owner