Post Link and Pictures to User Timeline using facebook JavaScript SDK

Updated on     Kisan Patel

Here we take a look at how to post link and pictures to user’s timeline with the Feed dialog using facebook JavaScript SDK.

You can do this through the FB.ui method of the JavaScript SDK.

So first load JavaScript SDK asynchronously. To load JavaScript SDK add below line of code and Replace YOUR_APP_ID with your APP ID.

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
      appId : 'YOUR_APP_ID', // App ID
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml : true // parse XFBML

 // Additional initialization code here


// Load the JavaScript SDK Asynchronously
   var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
   js = d.createElement('script'); = id; js.async = true;
   js.src = "//";

Now you need to call the FB.ui method that allows you to trigger Facebook dialogs that can do things like publish stories, prompt user to add friends and etc. It’s really easy to use. You simply issue a call with certain parameters and the method pops up a dialog.

	method: 'feed',
	'link': myLink,
	'picture': '',
	'name': myTitle,
	'caption': 'View Source Blog',
	'description': myExcerpt
}, function(response) {
	if (response && response.post_id) {
		alert("Thanks. This has been posted onto your timeline.");
	} else {
		alert("The post was not published.");
	} //Response from post attempt
}); // Call to FB.ui

It’s Done!


Leave a Reply