Search code examples
androidfacebookfacebook-wall

How to submit Photos with text together to Facebook wall from Android?


i'm really stuck on this, i need to post a photo (byte[]) and text (String) to the Facebook Wall how to do that?

What i'm able to do now is, to upload an image and after that to send a text, so for this i do two post's and that's not cool!

I would appreciate a code example on how to do that?

Thank's in advance....


Solution

  • In the documentation of the User object, it says under the photos connection:

    You can post photos to a user's Wall on their behalf by issuing an HTTP POST request to PROFILE_ID/photos with the publish_stream permissions and the following parameters.

    The android fb sdk will do just that for you, it should look something like this:

    // facebook being either Facebook or AsyncFacebookRunner
    
    Bundle parameters = new Bundle();
    parameters.putString("message", "MESSAGE TO GO WITH THE IMAGE");
    parameters.putByteArray("source", imageBytes);
    
    facebook.request("me/photos", parameters, "POST");
    

    I haven't tested it, and kind of "glued" it together after reading the documentation, the source and some threads (Async API Requests, API Requests, Facebook.java, Util.java, Android post picture to Facebook wall). In the last link in the code it says that the parameter name is picture instead of the source that I used, but that's how it states in the documentation, check it out and see which one works.

    Also, you can use USER-ID/photoes instead of the me/photos graph object path, just make sure that you have the publish_stream permission.

    Next time you ask a question, try to be more specific, maybe add the code you have so far?