我在我的应用中运行此代码,并尝试将文本和图像发布到用户墙。目前它只发布文本。我想我已经错过了一些简单的东西,但会欣赏另一双眼睛检查一切或另一个样本。
非常感谢任何帮助。
Bundle bundle = new Bundle();
bundle.putString("message", "test update"); //'message' tells facebook that you're updating your status
bundle.putString(Facebook.TOKEN,accessToken);
bundle.putString("attachment", "{\"name\":\"My Test Image\","
+"\"href\":\""+"http://www.google.com"+"\","
+"\"media\":[{\"type\":\"image\",\"src\":\""+"http://www.google.com/logos/mucha10-hp.jpg"+"\",\"href\":\""+"http://www.google.com"+"\"}]"
+"}");
+"}");
//tells facebook that you're performing this action on the authenticated users wall, thus
// it becomes an update. POST tells that the method being used is POST
String response = facebook.request("me/feed",bundle,"POST");
答案 0 :(得分:2)
希望这对你有用
为facebook变量实用程序创建类
import android.app.Application;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook;
public class Utility extends Application{
public static Facebook mFacebook;
public static AsyncFacebookRunner mAsyncRunner;
public static String userUID;
public static final String ICON_URL = "http://i.imgur.com/6G1b7.png";
}
没有用于将图片发布到Facebook墙上的方法
public void postOnFacebookPicture(final Bitmap bitmap) {
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
Utility.mFacebook.setAccessToken(access_token);
}
if (expires != 0) {
Utility.mFacebook.setAccessExpires(expires);
}
if (!Utility.mFacebook.isSessionValid()) {
showErrorDialog(
"Facebook Account is not configure,Setting Facebook Account?",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try {
// Move to setting the facebook account
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
} else {
new Thread() {
@Override
public void run() {
int what = 0;
try {
String accessToken = mPrefs.getString("access_token",
null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
byte[] pictureData = bos.toByteArray();
Bundle bundle = new Bundle();
bundle.putByteArray("facebookPictureData", pictureData);
bundle.putString(Facebook.TOKEN, accessToken);
Utility.mFacebook.request("me/photos", bundle, "POST");
} catch (Exception e) {
what = 1;
}
mHandler.sendMessage(mHandler.obtainMessage(what));
}
}.start();
}
}
答案 1 :(得分:0)
在Facebook墙上发布文字和图片,check this link:
您可以使用媒体附件插入图像。