Reputation: 71
I am trying to uplaod an image in my wall, but it only updates an post. If there is any other way to upload an image, pls help me. I logged in with the facebook log_in button widget. I didn't create any facebook object.
public void image_load(){
Session session = Session.getActiveSession();
if (session.isOpened())
{
Bundle postParams = new Bundle();
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap bi = BitmapFactory.decodeResource(getResources(),R.drawable.afzal);
bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
//postParams.putByteArray("picture", data);
postParams.putString("name", "Name here.");
postParams.putString("caption", "Caption here.");
postParams.putString("description", "Description here.");
//postParams.putString("message", "This is message");
postParams.putByteArray("source", data);
//postParams.putString("method", "photos.upload");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), postParams))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(MainActivity.this,
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(MainActivity.this,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(MainActivity.this,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(MainActivity.this,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
else{
Toast.makeText(MainActivity.this, "Please login first", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 1
Views: 2805
Reputation: 544
You may want to try adding a parameter with picture url.
Example
postParams.putString("picture", PICTURE_URL_HERE );
Hope this helps.
Upvotes: 1
Reputation: 15662
See the Feed dialog documentation here:
https://developers.facebook.com/docs/reference/dialogs/feed/
The "source" parameter only accepts URLs. If you want to upload an image, you should get the publish_actions permissions from the user, and use Request.newUploadPhotoRequest method.
Upvotes: 1