答案 0 :(得分:15)
答案 1 :(得分:2)
你可以这样做:
byte[] data = null;
try {
ContentResolver cr = mainActivity.getContentResolver();
InputStream fis = cr.openInputStream(localSnapshotUri);
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener());
这里使用的参数是:
localSnapshotUri
指向你/ sdcard / ..或任何地方的某些图像:) mainActivity
这是应用主要活动SampleUploadListener
AsyncFacebookRunner.RequestListener
interface 有一个很好的编程!
答案 2 :(得分:2)
刚刚在这里发布了上传照片的简单方法:
android facebook publish photo
代码:
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile(photoToPost);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
答案 3 :(得分:1)
到目前为止,最简单且最有效的例子是在没有登录对话框的情况下发布到用户的墙上,并使用新的Facebook SDK,它是: http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
顺便说一句,发布图像的方法是:
parameters.putString("picture", "http://www.google.com/logos/mucha10-hp.jpg");