简体   繁体   中英

upload a bitmap to facebook from android app

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM