Upload photos to Facebook wall/album from Android

I have downloaded the Facebook Android SDK from Git and followed the steps as in developers.facebook and got an application ID and run some sample code. I can post status on the wall. Now I am trying to upload a photo on the wall with a description or caption, but I can't. I browsed and mostly I found the following code as answer for photo-upload.

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

For this, I got the response as {"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=198930480222970&set=a.198930373556314.43760.100003180585600&type=1","caption":"So Cuuteee!!","created":1333718624,"object_id":198930480222970}

The photo is uploaded somewhere (it gives some URL) as a small size picture. But not on the Facebook wall or Album. By seeing Stack Overflow question Android - How to upload photo from the SD card to the Facebook wall, I tried

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

and

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

For both, I got the following as response

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

How do I upload on the wall?

Answers


See the source code at https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook/src/com/facebook/android.

It contains source code on how to upload an image.


Does your application have the permission photo_upload to upload photo to Facebook?

Try this code:

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

Need Your Help

How to run the onlick command after I choose the item in drop down menu?

javascript drop-down-menu onclick

Every time i click on the dropdown menu , the onlick trigger the function reload straight away. How can i make the function reload run after i select the item in the drop down menu list? Please hel...

When to separate certain entities into different repositories?

c# .net design-patterns domain-driven-design repository-design

I generally try and keep all related entities in the same repository. The following are entities that have a relationship between the two (marked with indentation):