0

I want to upload both a message and a PNG image to the logged-in user's timeline using facebook sdk in android.

The response rarely succeed, but failed in most cases.

The error response is "Response: responseCode: 408, graphObject: null, error: {HttpStatus: 408, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false".

Why the 408 error happens?

Here is my code:

private void postMessageAndPhoto() {

    Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
    String message = "Hello. \n https://developers.facebook.com/android";
    Bundle postParams = new Bundle();
    postParams.putString("message", message);
    postParams.putParcelable("picture", image);
    Request request = new Request(Session.getActiveSession(), "me/photos", postParams,
            HttpMethod.POST, new Request.Callback() {
                @Override
                public void onCompleted(Response response) {
                    if (!isFinishing()) {
                      // do something
                    }
                }
            });
    request.executeAsync();

}

How should I post a messages and a photos?

  • The 408 error is an HTTP error which is triggered when a request times out. It is most likely that your request to upload the image/post is taking too long or failing due to connectivity issues. Furthermore, I would suggest using the `Request` class' `newUploadPhotoRequest` method as used in the SDK. For a full example, [look at this excellent answer](http://stackoverflow.com/a/20998517/716588) on S.O. – CodeMonkey Dec 24 '14 at 03:21
  • Thank you for your anser. This cause seems due to connectivity issues as you said. – user4384543 Dec 24 '14 at 04:55
  • Awesome, glad it worked! I have posted my comment as an answer so that others can learn from it if need be. Feel free to mark it as the correct answer. – CodeMonkey Dec 24 '14 at 05:36

1 Answers1

0

The 408 error is an HTTP error which is triggered when a request times out. It is most likely that your request to upload the image/post is taking too long or failing due to connectivity issues.

As a side note, I would suggest using the Request class' newUploadPhotoRequest method as used in the SDK. For a full example, look at this excellent answer on S.O.

Community
  • 1
  • 1
CodeMonkey
  • 1,426
  • 1
  • 14
  • 32