简体   繁体   中英

Android post image on facebook wall

I have tried many code to send the image on facebook wall but it is not working. I am using this code

Bitmap bitmap =  BitmapFactory.decodeResource(shareDialogContext.getResources(),R.drawable.splash);

byte[] byetArray = convertBitmapToByteArray(shareDialogContext,bitmap);
params.putByteArray("picture",byetArray);
objFacebook.request(profileID + "me/photos", params, "POST");
public byte[] convertBitmapToByteArray(Context context, Bitmap bitmap) {
 ByteArrayOutputStream buffer = new ByteArrayOutputStream(bitmap.getWidth() * 
     bitmap.getHeight());
     bitmap.compress(CompressFormat.PNG, 100, buffer);
     return buffer.toByteArray();                 

}

Please suggest any useful code.

Doesn't hackbook example do exactly what you want?

                Bundle params = new Bundle();
                try {
                    params.putByteArray("photo",
                            Utility.scaleImage(getApplicationContext(), photoUri));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                params.putString("caption", "FbAPIs Sample App photo upload");
                Utility.mAsyncRunner.request("me/photos", params, "POST",
                        new PhotoUploadListener(), null);

This may help you:

 Bundle params = new Bundle();
 try 
 {
     params.putByteArray("photo",Utility.scaleImage(getApplicationContext(), photoUri));
 }
 catch (IOException e) 
 {
     e.printStackTrace();
 }
 params.putString("caption", "Through My Android Application");
 Utility.mAsyncRunner.request("me/photos", params, "POST",new PhotoUploadListener(), null);

Possible duplicate : Android - Upload photo to Facebook with Facebook Android SDK

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