我试图在我的墙上竖起一张图片,但它只更新了一个帖子。如果还有其他方式上传图片,请帮助我。我使用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();
}
}
答案 0 :(得分:1)
请参阅此处的Feed对话框文档:
https://developers.facebook.com/docs/reference/dialogs/feed/
“source”参数仅接受网址。如果您要上传图片,则应获取用户的publish_actions权限,并使用Request.newUploadPhotoRequest方法。
答案 1 :(得分:1)
您可能想尝试添加带图片网址的参数 示例
postParams.putString("picture", PICTURE_URL_HERE );
希望这有帮助。