I have the following code.
It works and posts the message-part but the attachment part does\'nt work. I suspect it has to do with passing a JSON as a string.
Fac
You can't send json encoded data to facebook, doesn't work that way. Each parameter should be on it's on in the POST body.
In addition, the "attachment" way is an old one and not used anymore. It should look something like:
Bundle params = new Bundle();
params.putString("message", message);
params.put("name", "Cricket Fantasy");
params.put("caption", "New team");
params.put("description","Description about Application");
params.put("url", URLEncoder.encode("http://a.espncdn.com/photo/2010/0523/pg2_a_cricket_576.jpg"));
String response = mFacebook.request("me/feed", params, "POST");
An official reference for uploading images using urls can be found here: Uploading Photos to the Graph API via a URL. The parameters for posting to a feed can be found in the User object doc.
Bundle params = new Bundle();
// params.putString("multipart/form-data", imgurl);
params.putByteArray("multipart/form-data",byteArray);
params.putString("caption", txtcaption.getText().toString());
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.e("responseImagedata---", response.toString());
}
}
).executeAsync();