<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>radio qupido</title>
	<atom:link href="http://www.radioqupido.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.radioqupido.com</link>
	<description>Solo un altro sito WordPress</description>
	<lastBuildDate>Sat, 12 Nov 2011 09:36:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ascoltare Click su Like button e commenti nella Comments box</title>
		<link>http://www.radioqupido.com/facebook/07-11-2011/ascoltare-click-su-like-button-e-commenti-nella-comments-box</link>
		<comments>http://www.radioqupido.com/facebook/07-11-2011/ascoltare-click-su-like-button-e-commenti-nella-comments-box#comments</comments>
		<pubDate>Mon, 07 Nov 2011 20:39:22 +0000</pubDate>
		<dc:creator>Michele Salvini</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[integrazione]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[like button]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.radioqupido.com/?p=6</guid>
		<description><![CDATA[Questo esempio spiega come poter gestire i click sul pulsante Like e i commenti nel plugin fb:comments di Facebook inseriti nel proprio sito web Ascoltare il click sul pulsante Like button e sul pulsante Send button o l&#8217;inserimento di un commento nel plugin Comments box si può fare usando questo codice: &#60;script charset=&#34;utf-8&#34; type=&#34;text/javascript&#34; src=&#34;http://connect.facebook.net/it_IT/all.js&#34;&#62;&#60;/script&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Questo esempio spiega come poter gestire i click sul pulsante Like e i commenti nel plugin fb:comments di Facebook inseriti nel proprio sito web</p>
<p>Ascoltare il click sul pulsante Like button e sul pulsante Send button o l&#8217;inserimento di un commento nel plugin Comments box si può fare usando questo codice:</p>
<pre class="wp-code-highlight prettyprint">
&lt;script charset=&quot;utf-8&quot; type=&quot;text/javascript&quot; src=&quot;http://connect.facebook.net/it_IT/all.js&quot;&gt;&lt;/script&gt;
&lt;script charset=&quot;utf-8&quot; type=&quot;text/javascript&quot;&gt;
function setFacebook(){
  FB.init({ appId:'APP_ID', cookie:true, status:true, xfbml:true });
  FB.Event.subscribe('edge.create',function(href){
    voteFromFB( href1 );
  });
  FB.Event.subscribe('message.send',function(href){
    voteFromFB( href2 );
  });
  FB.Event.subscribe('comment.create',function(comment){
    commentFromFB( comment );
  });
}
&lt;/script&gt;
</pre>
<p>I primi 2 argomenti &#8220;href1&#8243; e &#8220;href2&#8243; dei log saranno gli url del like che verrà pubblicato su FB, il terzo argomento &#8220;comment&#8221; è invece un oggetto:</p>
<pre class="wp-code-highlight prettyprint">
{
  &quot;commentID&quot; : &quot;7124678124012745120874&quot;,
  &quot;href&quot; : &quot;href indicato nel tag  &lt;fb:comments&gt;&quot;
}
</pre>
<p>La funzione commentFromFB può essere scritta così con Mootools e con jQuery:</p>
<pre class="wp-code-highlight prettyprint">
// Mootools
function commentFromFB( comment ){
var Req = new Request.JSON({
  url: 'script.php',
  onSuccess: function( json ){
    if( json.success ){
      alert( json.last_comment );
    } else {
      alert( 'Errore' );
    }
  }
}).post({
  'handle_comment': true,
  'href_comment': comment.href
});
}
// jQuery
function commentFromFB( comment ){
$.post( &quot;script.php&quot;,
  { 'handle_comment': true, 'href_comment': comment.href },
  function(data){
    if( data.success ){
      alert( data.last_comment );
    } else {
      alert( 'Errore' );
    }
  },
  &quot;json&quot;
);
}
</pre>
<p>il file script.php gestisce la chiamata così:</p>
<pre class="wp-code-highlight prettyprint">
&lt;?php
$out = array( 'comments' =&gt; '' );

if( isset( $_POST['handle_comment'] ) ){
/*

     invio all'url https://graph.facebook.com/comments/ il parametro GET ?id='.$_POST['href_comment']...
     ad esempio https://graph.facebook.com/comments/?id=www.esempio.com

*/
  $comments = json_decode( file_get_contents( 'https://graph.facebook.com/comments/?id='.$_POST['href_comment'] ), true );

  if(count($comments['data'])){

    $last_comment = $comments['data'][ count($comments['data']) - 1 ];

/*
     $last_comment sarà un array così composto:
     {
         &quot;id&quot;: &quot;524727245724&quot;,
         &quot;from&quot;: {
            &quot;name&quot;: &quot;Nome Cognome&quot;,
            &quot;id&quot;: &quot;id utente FB&quot;
         },
         &quot;message&quot;: &quot;Testo del messaggio&quot;,
         &quot;created_time&quot;: &quot;2011-11-07T21:41:06+0000&quot;
     }
     potete quindi utilizzarlo come volete nel vostro backend
*/
    $out = array( 'success' =&gt; true, 'last_comment' =&gt; $last_comment['comment'] );

  } else {

    $out = array( 'success' =&gt; true, 'last_comment' =&gt; 'Nessun messaggio' );

  }
}
?&gt;
</pre>
<p>A questo punto nel browser visualizzerete l&#8217;alert con il testo del messaggio per testare il funzionamento dello script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.radioqupido.com/facebook/07-11-2011/ascoltare-click-su-like-button-e-commenti-nella-comments-box/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

