-1

我已经从Git下载了 Facebook Android SDK,并按照developers.facebook中的步骤进行操作,获得了应用程序 ID 并运行了一些示例代码。我可以在墙上发布状态。现在我想在墙上上传一张带有描述或标题的照片,但我不能。我浏览并发现以下代码作为照片上传的答案。

public void postImageonWall() {
    byte[] data = null;

    Bitmap bi = BitmapFactory.decodeFile("/sdcard/cutedog.jpg");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();
    Bundle params = new Bundle();
    params.putString(Facebook.TOKEN, mFacebook.getAccessToken());
    params.putString("method", "photos.upload");
    params.putByteArray("picture", data);
    params.putString("caption", "So Cuuteee!!");
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
}

为此,我得到的响应为 {"pid":"100003180585600_320223","aid":"100003180585600_43760","owner":100003180585600,"src":"http://photos-g.ak.fbcdn.net/ hphotos-AK-PRN1 / 533575_198930480222970_100003180585600_320223_995139351_s.jpg “ ”src_big“: ”http://a7.sphotos.ak.fbcdn.net/hphotos-ak-prn1/s720x720/533575_198930480222970_100003180585600_320223_995139351_n.jpg“, ”src_small“:” HTTP: //photos-g.ak.fbcdn.net/hphotos-ak-prn1/533575_198930480222970_100003180585600_320223_995139351_t.jpg","link":"http://www.facebook.com/photo.php?fbid=1989304802293770&set56002293673&set56148.jpg 100003180585600&type=1","caption":"So Cuuteee!!","created":13337186​​24,"object_id":198930480222970}

照片以小尺寸图片的形式上传到某个地方(它提供了一些 URL)。但不在 Facebook 墙上或相册上。通过查看 Stack Overflow 问题Android - How to upload photo from SD card to the Facebook wall,我尝试了

    mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener(), null);

    mAsyncRunner.request("me/feed", params, "POST", new SampleUploadListener(), null);

对于两者,我得到以下回应

   {"error":{"message":"Unsupported method, photos.upload","type":"Exception"}}

怎么上传到墙上?

4

2 回答 2

3

您的应用程序是否有权photo_upload将照片上传到 Facebook?

试试这个代码:

Bundle params = new Bundle();
params.putString("method", "photos.upload");

FileInputStream in;
BufferedInputStream buf;
try {
    File file = new File("/sdcard/cutedog.jpg");

    in = new FileInputStream(file);
    buf = new BufferedInputStream(in,1070);

    byte[] bMapArray= new byte[buf.available()];
    buf.read(bMapArray);
    params.putByteArray("picture", bMapArray);
} catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

mAsyncRunner.request(null, params, "POST",new SampleUploadListener(), null);
于 2012-04-06T14:00:48.563 回答
0

参见源代码https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook/src/com/facebook/android

它包含有关如何上传图像的源代码。

于 2012-04-06T20:43:11.420 回答