0

I am using SDK 3.6 for posting the message and Photo. The below code is giving the response like "Unsupported Methods, Photos.upload "

I referred the below Stackoverflow.

Android post picture to Facebook wall

Is there anything Wrong?. How to upload the Image (not from url), and message together in facebook

private void postPhoto1()
{
if (hasPublishPermission()) {
Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
Session session = Session.getActiveSession();
Bundle postParams = new Bundle();
Byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParams.putString("method", "photos.upload");
postParams.putByteArray("picture", data);
Request request = new Request(session, "me/photos", postParams, HttpMethod.POST, new Request.Callback() {
     @Override
   public void onCompleted(Response response) {
   showPublishResult(getString(R.string.successfully_posted_post), response.getGraphObject(), response.getError());
  }
 });
     RequestAsyncTask task = new RequestAsyncTask(request);
     task.execute();
      } else {
   pendingAction = PendingAction.POST_PHOTO;
  }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
user3127462
  • 223
  • 1
  • 3
  • 12

2 Answers2

0

I removed this and its posting it.

postParams.putString("method", "photos.upload");

And message also its successfully posting along with image, using the below lines.

postParams.putByteArray("picture", data);
postParams.putString("message", messageval );
user3127462
  • 223
  • 1
  • 3
  • 12
-1

try this code if you get publish permission

public void postImage(){
     byte[] data = null;               

     File imagefile = new File(Path);
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(imagefile);
            } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        Bitmap bm = BitmapFactory.decodeStream(fis);
         ByteArrayOutputStream baos=new  ByteArrayOutputStream();
         bm.compress(Bitmap.CompressFormat.JPEG,100, baos);             
        data = baos.toByteArray();                
        Bundle params = new Bundle();              
        params.putString(Facebook.TOKEN, facebook.getAccessToken());              
        params.putString("method", "photos.upload");              
        params.putByteArray("picture", data);               
        AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);              
        mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);   
        Toast.makeText(getApplicationContext(), "Image Posted on Facebook.", Toast.LENGTH_SHORT).show();

}
ChrisF
  • 134,786
  • 31
  • 255
  • 325
HM.Rajjaz
  • 369
  • 1
  • 3
  • 17