0

这是将图片上传到我的 facebook 的代码:

Bundle parameters = new Bundle();
parameters.putString("message", msg);
byte[] imgData = getImage("http://bandungraos.in/wp-content/resto/1/gallery/kepiting1.jpg");
parameters.putByteArray("picture", imgData);
if (imgData != null) {
    try {
        String response = facebook.request("me/photos", parameters,"POST");
            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
}
.....

private byte[] getImage(String url) {

    try {
        URL imgUrl = new URL(url);
        HttpURLConnection cn = (HttpURLConnection) imgUrl.openConnection();
        cn.setDoInput(true);
        cn.connect();
        int length = cn.getContentLength();
        byte[] imgData = new byte[length];
        InputStream is = cn.getInputStream();
        is.read(imgData);
        return imgData;

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;

}

我检查了访问令牌或 imgData 是否不为空

没有错误,但我在我的 facebook 中找不到该图像。

提前致谢

4

2 回答 2

0

我有同样的问题,我使用了这段代码`

private void upload_FB(Bitmap photo2) {
        // TODO Auto-generated method stub
        Calendar c = Calendar.getInstance();
        String name = c.getTime().toString();

        AsyncFacebookRunner fruner = new AsyncFacebookRunner(facebook);
        Log.d("adr", mCurrentPhotoPath);
        if(photo2!=null && mCurrentPhotoPath!=null){
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            photo2.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            byte[] bMapArray = baos.toByteArray();
            Bundle params = new Bundle();
            params.putByteArray("photo",bMapArray);
            params.putString("caption", name);
            fruner.request("me/photos",params,"POST",new PhotoUploadListener(),null);


        }else
            Toast.makeText(ctx, "ERROR", Toast.LENGTH_LONG).show();
    }

不要忘记添加前提photo_upload `

于 2012-07-02T11:37:05.827 回答
0

根据有关照片连接的用户对象文档,图像参数被命名为"source"而不是"picture",您是否尝试过:

Bundle parameters = new Bundle();
parameters.putString("message", msg);
parameters.putByteArray("source", getImage("..."));
于 2012-05-21T08:42:50.173 回答