我正在尝试在我的墙上上传一张图片,但它只会更新一个帖子。如果有其他上传图片的方法,请帮助我。我使用 facebook log_in 按钮小部件登录。我没有创建任何 facebook 对象。
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();
}
}