在网上看了两天终于决定发帖了。
好吧,我只是想在我的 Android 应用程序中将一张照片发布到 Facebook。
AM 使用官方的 android-facebook-sdk。我导入到示例项目并在上传部分添加我的代码以上传照片。喜欢
mUploadButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Bundle params = new Bundle();
params.putString("method", "photos.upload");
Bitmap temp = BitmapFactory.decodeResource(getResources(),R.drawable.facebook_icon);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
temp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imgData = baos.toByteArray();
params.putByteArray("picture", imgData);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener());
}
});
但是它没有用:(
我也浏览了这个论坛中的链接: Looking for android Facebook SDK examples
但我无法发帖。 :(
请帮助我。谢谢。
最佳答案
看看这个。
Looking for android Facebook SDK examples
编辑: 刚刚开始工作。这是在 postToWall() 函数下的 ShareOnFacebook 类中。
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);
编辑:
制定 Intent 时:
result 是图像在设备上的路径。
Intent postOnFacebookWallIntent = new Intent(getApplicationContext(), ShareOnFacebook.class);
postOnFacebookWallIntent.putExtra("facebookMessage", facebookMessage);
postOnFacebookWallIntent.putExtra("facebookPhoto", result);
startActivity(postOnFacebookWallIntent);
关于android facebook 发布照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4647767/