我正在尝试从我的android项目的drawable文件夹上传Facebook墙上的一个图像。但是我很失败......墙上显示的信息却显示在墙上但图像不在墙上。 我的示例代码如下所示。
Drawable drawable = ClassName.this.getResources().getDrawable(R.drawable.ic_launcher);
Bitmap bitmap = (Bitmap)((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitMapData = stream.toByteArray();
Bundle params = new Bundle();
params.putString("message", "Tarun Kumar");
params.putString("name", "MY Image");
params.putByteArray("picture", bitMapData);
mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());
它在Log上显示一些错误..比如
10-03 12:55:55.664: W/Bundle(529): Key message expected byte[] but value was a java.lang.String. The default value <null> was returned.
10-03 12:55:55.914: D/dalvikvm(529): GC_FOR_MALLOC freed 6599 objects / 465168 bytes in 225ms
10-03 12:55:55.924: W/Bundle(529): Attempt to cast generated internal exception:
10-03 12:55:55.924: W/Bundle(529): java.lang.ClassCastException: java.lang.String
10-03 12:55:55.924: W/Bundle(529): at android.os.Bundle.getByteArray(Bundle.java:1305)
10-03 12:55:55.924: W/Bundle(529): at com.facebook.android.Util.openUrl(Util.java:155)
10-03 12:55:55.924: W/Bundle(529): at com.facebook.android.Facebook.request(Facebook.java:559)
10-03 12:55:55.924: W/Bundle(529): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:208)
10-03 12:55:55.924: W/Bundle(529): Key format expected byte[] but value was a java.lang.String. The default value <null> was returned.
10-03 12:55:55.924: W/Bundle(529): Attempt to cast generated internal exception:
10-03 12:55:55.924: W/Bundle(529): java.lang.ClassCastException: java.lang.String
10-03 12:55:55.924: W/Bundle(529): at android.os.Bundle.getByteArray(Bundle.java:1305)
10-03 12:55:55.924: W/Bundle(529): at com.facebook.android.Util.openUrl(Util.java:155)
10-03 12:55:55.924: W/Bundle(529): at com.facebook.android.Facebook.request(Facebook.java:559)
10-03 12:55:55.924: W/Bundle(529): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:208)
10-03 12:55:55.984: W/Bundle(529): Key access_token expected byte[] but value was a java.lang.String. The default value <null> was returned.
10-03 12:55:55.984: W/Bundle(529): Attempt to cast generated internal exception:
10-03 12:55:55.984: W/Bundle(529): java.lang.ClassCastException: java.lang.String
10-03 12:55:55.984: W/Bundle(529): at android.os.Bundle.getByteArray(Bundle.java:1305)
10-03 12:55:55.984: W/Bundle(529): at com.facebook.android.Util.openUrl(Util.java:155)
10-03 12:55:55.984: W/Bundle(529): at com.facebook.android.Facebook.request(Facebook.java:559)
10-03 12:55:55.984: W/Bundle(529): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:208)
10-03 12:55:55.984: D/webviewglue(529): nativeDestroy view: 0x27a548
10-03 12:55:56.014: W/Bundle(529): Key name expected byte[] but value was a java.lang.String. The default value <null> was returned.
10-03 12:55:56.014: W/Bundle(529): Attempt to cast generated internal exception:
10-03 12:55:56.014: W/Bundle(529): java.lang.ClassCastException: java.lang.String
10-03 12:55:56.014: W/Bundle(529): at android.os.Bundle.getByteArray(Bundle.java:1305)
10-03 12:55:56.014: W/Bundle(529): at com.facebook.android.Util.openUrl(Util.java:155)
10-03 12:55:56.014: W/Bundle(529): at com.facebook.android.Facebook.request(Facebook.java:559)
10-03 12:55:56.014: W/Bundle(529): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:208)
答案 0 :(得分:2)
如果将图片从app发布到fb,则无法使用 me / feed 参数,您必须使用照片,并且请求
mAsyncFbRunner.request("photos", parameters,
"POST", new WallPostListener());