android facebook发布照片 [英] android facebook publish photo

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

问题描述

在网上看了2天后,我终于决定在SO上发布。



我只想在我的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。
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());
}
} );

但它可以工作:(



我在这个论坛里也经历过这样的链接:
寻找android Facebook SDK示例



但无法发布。(



请帮助我。

解决方案

看看这个。



拨打Android Facebook SDK示例



编辑:
只是这样工作,这是在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 = n ew Bundle();
params.putString(method,photos.upload);
params.putByteArray(picture,data);

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null,params,POST,new SampleUploadListener(),null);

编辑:





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

  Intent postOnFacebookWallIntent = new Intent(getApplicationContext(),ShareOnFacebook.class); 
postOnFacebookWallIntent.putExtra(facebookMes​​sage,facebookMes​​sage);
postOnFacebookWallIntent.putExtra(facebookPhoto,结果);
startActivity(postOnFacebookWallIntent);


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

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

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

But it doent work :(

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

but am not able to post. :(

Kindly help me.THanks.

解决方案

Take a look at this.

Looking for android Facebook SDK examples

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

EDIT:

When making the Intent:

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

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

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