Reputation: 190
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("picture", bitmap);
jsonObject.put("message","just a message");
} catch (JSONException e) {
e.printStackTrace();
}
GraphRequest graphRequest = GraphRequest.newPostRequest(AccessToken.getCurrentAccessToken(), "me/photos", jsonObject, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
Log.d("", "------ graphResponse = " + graphResponse);
}
});
graphRequest.executeAsync();
And is returning
graphResponse = {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}}
Please in Json Object param what i need to pass?
thanks
Upvotes: 1
Views: 3629
Reputation: 41
public void postToFacebook(){
final EditText message = (EditText) findViewById(R.id.editText);
if(AccessToken.getCurrentAccessToken() != null){
/* Bitmap image=BitmapFactory.decodeResource(getResources(),R.drawable.ll);
ByteArrayOutputStream blob1=new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG,0,blob1);
byte[] bitmapdata = blob1.toByteArray();*/
Bitmap image=BitmapFactory.decodeResource(getResources(), R.drawable.ll);
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(),
R.drawable.ll);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
// parameters.putByteArray("image", bitmapdata);
GraphRequest graphRequest = GraphRequest.newPostRequest(AccessToken.getCurrentAccessToken(), "me/photos", null, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
}
});
Bundle postParams = graphRequest.getParameters();
postParams.putByteArray("picture", data);
postParams.putString("caption", message.getText().toString());
graphRequest.setParameters(postParams);
graphRequest.executeAsync();
}
else
{
Toast.makeText(AndroidFacebookConnectActivity.this,"You are not logged into Facebook", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 1
Reputation: 516
instead of passing the json object, just pass the bundle one.
GraphRequest request = GraphRequest.newPostRequest(token,
"me/photos", null, callback2);
Bundle postParams = request.getParameters();
postParams.putByteArray("picture", MyUtils.FileToBytes("path to local file"));
postParams.putString("caption", "my picture");
request.setParameters(postParams);
request.executeAsync();
Upvotes: 5
Reputation: 15662
newPostRequest is for creating GraphObjects, and not for photos. Using v4.0 of the SDK, you should create a ShareContent, and then share it using the ShareApi, something like:
Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image);
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() { ...});
See https://developers.facebook.com/docs/sharing/android for more info.
Upvotes: 0