Post Image on Facebook using java api to publish on Wall

First Follow the listed Steps from my Previous post then in last program include the below code to publish a photo and also meta data on a facebook wall.

In the same way we can even publish MP3, Videos, Flash on facebook.

Publishing a Post Containing an Image, Action Links and Custom Metadata.

package com.unical;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpClientParams;


public class SendtoFacebook {

	public static void main (String a[]) throws FacebookException{ 

	SendtoFacebook sfb=new SendtoFacebook();
	sfb.send("From My App: publish steven on facebook");
	public void send(String message)throws FacebookException{

		String FB_APP_API_KEY = new String("YOUR APIKEY");
		String FB_APP_SECRET = new String("YOUR SECRET");
		String FB_SESSION_KEY = new String("YOUR SESSION KEY");
		FacebookJsonRestClient facebook = new FacebookJsonRestClient( FB_APP_API_KEY, FB_APP_SECRET, FB_SESSION_KEY );

		//FacebookJsonRestClient facebookClient2 = (FacebookJsonRestClient)facebook.getFacebookRestClient();
		FacebookJsonRestClient facebookClient = (FacebookJsonRestClient)facebook;
		Attachment attachment = new Attachment();
		attachment.setCaption("Caption for attachment");
		attachment.setDescription("Description for attachment");
		attachment.setName("Hopefully this works");

		AttachmentMediaImage  attach_media = new AttachmentMediaImage( );
		attach_media.addImage("", "");


		facebookClient.stream_publish(message, attachment, null, null, null);

			System.out.println("successfully updated");

6 thoughts on “Post Image on Facebook using java api to publish on Wall”

  1. Thanks a lot for the post… however I cant see the image in the post, but apart from the picture everything gets updated successfully on my wall… what could be the problem?

  2. You need to give a public URL and not your local system URL. try some url from flickr or something else.

  3. i am attaching video in the same way using AttachmentMediaVideo.
    But it is uploading only the image and details. when i click on that it wont play the video. right click shows movie not loaded.. any help!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image