1

I was writing the code for uploading image to facebook album "Profile Images", after selecting the image from gallery it is converted to byte array imageBytes and send to the AsyncTask. I use the fallowing code to upload the image. facebookProfileImagesAlbumId has the Id for the album "Profile Images"

 Bundle params_ = new Bundle();
 String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);

 params_.putString("source", encodedImage);
 /* make the API call */
 new GraphRequest(
        AccessToken.getCurrentAccessToken(),
        "/"+facebookProfileImagesAlbumId+"/photos",
        params_,
        HttpMethod.POST,
        new GraphRequest.Callback() {
              public void onCompleted(GraphResponse response) {
                   Log.i("Login", response.toString());
              }
        }).executeAndWait();

but it is not working and Log.i("Login", response.toString()); gives the following message

{Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: could not construct request body}}

I am using Facebook Graph API 2.4

Sarath Babu
  • 923
  • 3
  • 10
  • 27

1 Answers1

1

I have used following code to Post image to facebook wall or specific album.

public void PostImage(Bitmap bitmap) {
        AccessToken token = AccessToken.getCurrentAccessToken();
        if (token != null) {
            Bundle parameters = new Bundle(2);
            parameters.putParcelable("source", bitmap);
            parameters.putString("message", "description");
            new GraphRequest(token, "/"+facebookProfileImagesAlbumId+"/photos", parameters, HttpMethod.POST, new GraphRequest.Callback() {

                public void onCompleted(GraphResponse response) {
                    Log.e("Image Post", "Res =" + response.toString());
                }
            }).executeAsync();
        }
    }

Hope this helps!

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
  • but getting another error {Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 220, errorType: OAuthException, errorMessage: (#220) Album or albums not visible}}, I know it is not related to code – Sarath Babu Aug 20 '15 at 07:49
  • facebookProfileImagesAlbumId value is proper? or first just try "me/photos" instead of "/"+facebookProfileImagesAlbumId+"/photos". – Rajesh Jadav Aug 20 '15 at 07:50
  • 1
    You can not upload to the user’s profile pictures album any more. You can only upload to an album created for your app (Facebook will do that automatically, if you post to `/me/photos`), and then the user can select to use that image as their new profile image themselves via the Facebook UI. – CBroe Aug 20 '15 at 16:53