安卓的Facebook发布的照片照片、Facebook

2023-09-03 22:48:57 作者:浪女归家

看后在网上进行2天,我终于决定张贴在左右。

After looking on the net for 2 days I finally decided to post on SO.

嗯,我只是想在给Facebook发布在我的Andr​​oid应用程序中的照片。

Well I simply want to publish a photo in my android app on to facebook.

现在用的官方Android,Facebook的SDK。我导入示例项目,并在上传部分添加我的code上传照片。像

AM using the official android-facebook-sdk. I imported to example project and in the upload section add my code to upload photo. like

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());
    }
});

但doent工作:(

But it doent work :(

我经历了在这个论坛太喜欢的链接: 寻找Android的Facebook的SDK例子

I went through the links in this forum too like: Looking for android Facebook SDK examples

但我不能够发布。 :(

but am not able to post. :(

请帮me.THanks。

Kindly help me.THanks.

推荐答案

看看这个。

寻找Android的Facebook的SDK例子...

编辑: 刚刚得到这个工作。这是在postToWall()函数根据ShareOnFacebook类

Just got this working. This is in the ShareOnFacebook class under the postToWall() function.

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);

编辑:

在制作意图:

结果是路径到设备上的图像。

result is the path to the image on the device.

Intent postOnFacebookWallIntent = new Intent(getApplicationContext(), ShareOnFacebook.class);
postOnFacebookWallIntent.putExtra("facebookMessage", facebookMessage);
postOnFacebookWallIntent.putExtra("facebookPhoto", result);
startActivity(postOnFacebookWallIntent);