安卓的Facebook发布的照片 [英] android facebook publish photo

查看:170
本文介绍了安卓的Facebook发布的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看后在网上进行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);

这篇关于安卓的Facebook发布的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆