Facebook JDK / Publish Stream Issue

Hey all,

I am trying to publish a simple stream to facebook from my clients website, using FB.ui, but when I run the “streamPublish” method holding this code I just get “An error occurred. Please try again later.”

My code is as follows:-


<head>
	<title>A Dynamic Comment System</title>
	<meta http-equiv="content-type" 
		content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	
	<!-- Javascript Librairys -->
	<script src="http://connect.facebook.net/en_US/all.js"></script>
	<script type="text/javascript" src="javascripts/commentsystem.js"></script>

	<!-- Style Sheets -->
	<style type="text/css" media="all">
		@import "css/commentstyles.css";
	</style>	

		<script> 
           window.fbAsyncInit = function() { 
				FB.init({appId: "180166762023187", status: true, cookie: true, 
                xfbml: true}); 
            }; 

			(function() 
			{ 
				var e = document.createElement("script"); e.async = true; 
				e.src = document.location.protocol + "//connect.facebook.net/en_US/all.js"; 
				document.getElementById("fb-root").appendChild(e); 
			}());

			function streamPublish()
			{       
				FB.ui(  
						{   method: 'stream.publish',display:'popup', message: 'getting educated about Facebook Connect', attachment: 
							{      
								name: 'Connect', caption: 'The Facebook Connect JavaScript SDK', description: ('A small JavaScript library that allows you to harness ' +  'the power of Facebook, bringing the user\\'s identity, ' + 'social graph and distribution power to your site.'),
								href: 'http://github.com/facebook/connect-js'     
							},  action_links: [{ text: 'Code', href: 'http://github.com/facebook/connect-js' }],     
								user_message_prompt: 'Share your thoughts about Connect'  	
						},   
						function(response) 
						{     
							if (response && response.post_id) 
							{       
								alert('Post was published.');     
							} 
							else 
							{       
								alert('Post was not published.');     
							}   
						} );
			} 
		 </script>	
</head>

I am not all that familiar with the FB API, so I am totally stumped - any help much appreciated ! :slight_smile:

Oh and just for the record, stream.share works! but stream.publish doesent, which is what I need :slight_smile:

I try to avoid facebook as much as possible, but you could try over at the facebook platform developers forum

Hello pmw, I appreciate your help - I found out the problem after many hours sat infront the computer. The following block of JS needs to go after the

<div id="fb-root"></div> 

divs, rather than in the head. Its just a shame there was not mention of this in the FB API documentation - onwards and upwards :slight_smile:


<div id="fb-root"></div>   
	<script>
			(function() 
			{ 
				var e = document.createElement("script"); e.async = true; 
				e.src = document.location.protocol + "//connect.facebook.net/en_US/all.js"; 
				document.getElementById("fb-root").appendChild(e); 
			}());
	</script>