2

I spent the past few days looking thru almost every SO question about uploading an image to Facebook, and I still can't get it to work. This is what I've done so far: 1. Created an app on facebook and got the app id 2. dl'd the facebook sdk, along with the Example code they supply there (for the SampleUploadListener) 3. Added everything to the project, and used the code given in

Android - Upload photo to Facebook with Facebook Android SDK :

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

This doens't seem to work. The code compiles and everything runs, but no facebook popup appears and nothing gets posted in Facebook - the app just runs right through it.

Any suggestions?

Community
  • 1
  • 1
n00b programmer
  • 2,671
  • 7
  • 41
  • 56

1 Answers1

0

According to my knowledge you are right all the way, except for the "null" you have provided for the graph path in the request method. YOu should provide a value for graph path. Eg:"me/photos". Try this,

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

replace null with "me/photos" and check. It should work fine if this is the only problem with your code.

All the best.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • still nothing :( by the way, I'm writing this code inside a listener in my own app, should it be done from some sort of intent that starts the facebook app, or is it ok? Thanks! – n00b programmer Mar 02 '12 at 08:35
  • could u give it a try without params.putString("method", "photos.upload"); – Andro Selva Mar 02 '12 at 08:47
  • still nothing... I have a different problem that could be related: http://stackoverflow.com/questions/9526551/android-cant-find-com-facebook-android-apk although, when I compile just the facebook app and try to run it, it works to a certain extent - it logs me on and the crashes :) So, Idon't think that is the problem. – n00b programmer Mar 02 '12 at 09:56