Facebook app request in java not working
- by Arpit Solanki
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);
}