2

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.

Community
  • 1
  • 1
droid
  • 37
  • 1
  • 1
  • 4

1 Answers1

8

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);
Community
  • 1
  • 1
Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
  • If this answer has helped you. Please comment so others know it works. There are a lot of views but no feedback. – Anthony Graglia Mar 13 '11 at 10:46
  • 1
    can you plaz give any further expalnations on your answer? mostly as to where is the ShareOnFacebook class located, and what is the postOnFacebookWallIntent? Thanks! – n00b programmer Mar 02 '12 at 00:02
  • `mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);` I was using `"me/feed"` instead of `null` as graphPath (first parameter) and it didn't work. It works with null. Thank you – Bojan Radivojevic Jun 07 '12 at 17:27
  • The SDK and API have changed a lot since the original question and answer. – Anthony Graglia Jun 07 '12 at 19:43