<?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>blarnee.com &#187; facebook api application components</title>
	<atom:link href="http://blarnee.com/wp/tag/facebook-api-application-components/feed/" rel="self" type="application/rss+xml" />
	<link>http://blarnee.com/wp</link>
	<description>Web design and development online &#124; Adnan Osmani's blog</description>
	<lastBuildDate>Fri, 03 Sep 2010 18:35:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to create a Facebook Friend Selector using jQuery and PHP or Grails (without FBML)</title>
		<link>http://blarnee.com/wp/how-to-create-a-facebook-friend-selector-using-jquery-and-php-or-grails-without-fbml/</link>
		<comments>http://blarnee.com/wp/how-to-create-a-facebook-friend-selector-using-jquery-and-php-or-grails-without-fbml/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 05:38:38 +0000</pubDate>
		<dc:creator>legacye</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[facebook api application components]]></category>
		<category><![CDATA[facebook api friend selector]]></category>
		<category><![CDATA[facebook PHP components]]></category>
		<category><![CDATA[facebook php friend selector]]></category>
		<category><![CDATA[FBML]]></category>
		<category><![CDATA[friend selection]]></category>
		<category><![CDATA[friend selector]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[grails friend selector]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP friend selector]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://blarnee.com/wp/?p=416</guid>
		<description><![CDATA[When I first attempting to code up a pure PHP Facebook app, one of the first problem&#8217;s I encountered was I wanted to create a friend selector using as little FBML or FBJS code as possible. This proved slightly difficult as any external PHP file I would create to query Facebook using FQL via Ajax [...]


Related posts:<ol><li><a href='http://blarnee.com/wp/anatomy-of-a-facebook-application/' rel='bookmark' title='Permanent Link: Creating a Facebook Application &#8211; a simple guide for PHP, JavaScript, Flex and Grails developers.'>Creating a Facebook Application &#8211; a simple guide for PHP, JavaScript, Flex and Grails developers.</a> <small>&nbsp;If you&#8217;re a web developer and you haven&#8217;t explored the...</small></li><li><a href='http://blarnee.com/wp/creating-a-facebook-application-a-guide-for-php-javascript-flex-and-grails-developers/' rel='bookmark' title='Permanent Link: Creating a Facebook Application &#8211; a guide for PHP, JavaScript, Flex and Grails developers'>Creating a Facebook Application &#8211; a guide for PHP, JavaScript, Flex and Grails developers</a> <small> If you’re a web developer and you haven’t explored...</small></li><li><a href='http://blarnee.com/wp/how-to-create-impressive-animations-in-jquery-with-animate/' rel='bookmark' title='Permanent Link: How to create impressive animations in jQuery with .animate()'>How to create impressive animations in jQuery with .animate()</a> <small> I&#8217;ve been asked many times over the past month...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>When I first attempting to code up a pure PHP Facebook app, one of the first problem&#8217;s I encountered was I wanted to create a friend selector using as little FBML or FBJS code as possible. This proved slightly difficult as any external PHP file I would create to query Facebook using FQL via Ajax to return my friend&#8217;s array also required authentication (something that isn&#8217;t as much of a problem using Flash or Flex, but is using PHP or Grails) because it requires persistance across multiple files without having to ask the user to login to facebook again (if you&#8217;ve tried this you&#8217;ll know what I mean). Having searched online for a solution that didn&#8217;t require me to use a hacked up version of FBML..I decided to come up with a simple solution myself.</p>
<p><span id="more-416"></span></p>
<p>One way to work around this is by using JSON and the jQuery <a href="http://docs.jquery.com/Plugins/Autocomplete">AutoComplete</a> plugin. &nbsp;The AutoComplete component allows you to bind a data object to any input control to allow you to use autoComplete features on it. An example of how to enable this can seen below.&nbsp;</p>
<pre style="padding-top: 5px !important; padding-right: 5px !important; padding-bottom: 5px !important; padding-left: 5px !important; margin-top: 0.8em !important; margin-right: 0px !important; margin-bottom: 1.2em !important; margin-left: 0px !important; border-top-width: 1px !important; border-right-width: 1px !important; border-bottom-width: 1px !important; border-left-width: 1px !important; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 11px !important; vertical-align: baseline; background-image: initial !important; background-repeat: initial !important; background-attachment: initial !important; -webkit-background-clip: initial !important; -webkit-background-origin: initial !important; background-color: rgb(245, 244, 238) !important; color: rgb(6, 38, 60) !important; border-top-style: dotted !important; border-right-style: dotted !important; border-bottom-style: dotted !important; border-left-style: dotted !important; border-top-color: rgb(221, 221, 221) !important; border-right-color: rgb(221, 221, 221) !important; border-bottom-color: rgb(221, 221, 221) !important; border-left-color: rgb(221, 221, 221) !important; line-height: 1.6 !important; overflow-x: auto; overflow-y: auto; text-align: left; font-weight: normal; font-family: monaco, monospace; float: none; width: auto; -webkit-border-top-right-radius: 3px 3px; -webkit-border-top-left-radius: 3px 3px; -webkit-border-bottom-left-radius: 3px 3px; -webkit-border-bottom-right-radius: 3px 3px; background-position: initial initial !important; ">
var data = &quot;&quot;.split(&quot;John James Tom Cat Luke&quot;);</pre>
<pre style="padding-top: 5px !important; padding-right: 5px !important; padding-bottom: 5px !important; padding-left: 5px !important; margin-top: 0.8em !important; margin-right: 0px !important; margin-bottom: 1.2em !important; margin-left: 0px !important; border-top-width: 1px !important; border-right-width: 1px !important; border-bottom-width: 1px !important; border-left-width: 1px !important; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 11px !important; vertical-align: baseline; background-image: initial !important; background-repeat: initial !important; background-attachment: initial !important; -webkit-background-clip: initial !important; -webkit-background-origin: initial !important; background-color: rgb(245, 244, 238) !important; color: rgb(6, 38, 60) !important; border-top-style: dotted !important; border-right-style: dotted !important; border-bottom-style: dotted !important; border-left-style: dotted !important; border-top-color: rgb(221, 221, 221) !important; border-right-color: rgb(221, 221, 221) !important; border-bottom-color: rgb(221, 221, 221) !important; border-left-color: rgb(221, 221, 221) !important; line-height: 1.6 !important; overflow-x: auto; overflow-y: auto; text-align: left; font-weight: normal; font-family: monaco, monospace; float: none; width: auto; -webkit-border-top-right-radius: 3px 3px; -webkit-border-top-left-radius: 3px 3px; -webkit-border-bottom-left-radius: 3px 3px; -webkit-border-bottom-right-radius: 3px 3px; background-position: initial initial !important; ">
$(&quot;#friendSelectionInputBox&quot;).autocomplete(data);</pre>
<p>If you would like to test out the capabilities of the plugin a little further, why not take a look at the <a href="http://jquery.bassistance.de/autocomplete/demo/">demos</a> page :). You might have already guessed that what we are going to do is bind an array of data we get from the Facebook API directly to the autocomplete component. &nbsp;The first thing you&#8217;ll need to to is populate a PHP array with data from your friend&#8217;s list. Once you&#8217;re familiar with setting up Facebook API Objects, this is as simple as saying:</p>
<p>&nbsp;</p>
<pre style="padding-top: 5px !important; padding-right: 5px !important; padding-bottom: 5px !important; padding-left: 5px !important; margin-top: 0.8em !important; margin-right: 0px !important; margin-bottom: 1.2em !important; margin-left: 0px !important; border-top-width: 1px !important; border-right-width: 1px !important; border-bottom-width: 1px !important; border-left-width: 1px !important; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 11px !important; vertical-align: baseline; background-image: initial !important; background-repeat: initial !important; background-attachment: initial !important; -webkit-background-clip: initial !important; -webkit-background-origin: initial !important; background-color: rgb(245, 244, 238) !important; color: rgb(6, 38, 60) !important; border-top-style: dotted !important; border-right-style: dotted !important; border-bottom-style: dotted !important; border-left-style: dotted !important; border-top-color: rgb(221, 221, 221) !important; border-right-color: rgb(221, 221, 221) !important; border-bottom-color: rgb(221, 221, 221) !important; border-left-color: rgb(221, 221, 221) !important; line-height: 1.6 !important; overflow-x: auto; overflow-y: auto; text-align: left; font-weight: normal; font-family: monaco, monospace; float: none; width: auto; -webkit-border-top-right-radius: 3px 3px; -webkit-border-top-left-radius: 3px 3px; -webkit-border-bottom-left-radius: 3px 3px; -webkit-border-bottom-right-radius: 3px 3px; ">
$query = &quot;SELECT name, sex, pic_square FROM user  WHERE uid
IN ( SELECT uid2 FROM friend WHERE uid1= '$fb_user') &quot;;
$friends = $facebook-&gt;api_client-&gt;fql_query($query);</pre>
<p>Now that we have an arary of our friend information, the next thing we need to do is convert this to a format the autoComplete plugin can understand &#8211; namely JSON.&nbsp;</p>
<p>&nbsp;</p>
<pre style="padding-top: 5px !important; padding-right: 5px !important; padding-bottom: 5px !important; padding-left: 5px !important; margin-top: 0.8em !important; margin-right: 0px !important; margin-bottom: 1.2em !important; margin-left: 0px !important; border-top-width: 1px !important; border-right-width: 1px !important; border-bottom-width: 1px !important; border-left-width: 1px !important; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 11px !important; vertical-align: baseline; background-image: initial !important; background-repeat: initial !important; background-attachment: initial !important; -webkit-background-clip: initial !important; -webkit-background-origin: initial !important; background-color: rgb(245, 244, 238) !important; color: rgb(6, 38, 60) !important; border-top-style: dotted !important; border-right-style: dotted !important; border-bottom-style: dotted !important; border-left-style: dotted !important; border-top-color: rgb(221, 221, 221) !important; border-right-color: rgb(221, 221, 221) !important; border-bottom-color: rgb(221, 221, 221) !important; border-left-color: rgb(221, 221, 221) !important; line-height: 1.6 !important; overflow-x: auto; overflow-y: auto; text-align: left; font-weight: normal; font-family: monaco, monospace; float: none; width: auto; -webkit-border-top-right-radius: 3px 3px; -webkit-border-top-left-radius: 3px 3px; -webkit-border-bottom-left-radius: 3px 3px; -webkit-border-bottom-right-radius: 3px 3px; ">
$function generate_friend_array($facebook, $friends) {

	if (count($friends) &gt; 0 ) {
	$list_array = $facebook-&gt;api_client-&gt;users_getInfo($friends,
array('uid', 'last_name','first_name')); 

	// array sorting (friend list alphabetically)
	usort($list_array, 'cmpi');

	$return = &quot;var friend_array = []; &quot;;

	foreach ($list_array as $list_array_line) {
	$uid = $list_array_line['uid'];
	// insert slashes to escape potential ' in names
	$first_name = addslashes($list_array_line['first_name']);
	$last_name = addslashes($list_array_line['last_name']);
	$name = $first_name .&quot; &quot;. $last_name;
	$return .= &quot;

		friend_array.push(['&quot;.$uid.&quot;', '&quot;.$name.&quot;']);

	&quot;;	

	}

	return $return;
	} else {
	return &quot;var friend_array = 'none'&quot;;
	}
}</pre>
<p>&nbsp;</p>
<p>The array returned by this function should be valid JSON. For the purposes of this demo our array will only consist of your friend&#8217;s name and their UID. The last thing we <span style="font-size: medium; "><code>need to do is adjust our autoComplete component to understand the row format being output by the function.</code></span></p>
<p>&nbsp;</p>
<pre style="padding-top: 5px !important; padding-right: 5px !important; padding-bottom: 5px !important; padding-left: 5px !important; margin-top: 0.8em !important; margin-right: 0px !important; margin-bottom: 1.2em !important; margin-left: 0px !important; border-top-width: 1px !important; border-right-width: 1px !important; border-bottom-width: 1px !important; border-left-width: 1px !important; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 11px !important; vertical-align: baseline; background-image: initial !important; background-repeat: initial !important; background-attachment: initial !important; -webkit-background-clip: initial !important; -webkit-background-origin: initial !important; background-color: rgb(245, 244, 238) !important; color: rgb(6, 38, 60) !important; border-top-style: dotted !important; border-right-style: dotted !important; border-bottom-style: dotted !important; border-left-style: dotted !important; border-top-color: rgb(221, 221, 221) !important; border-right-color: rgb(221, 221, 221) !important; border-bottom-color: rgb(221, 221, 221) !important; border-left-color: rgb(221, 221, 221) !important; line-height: 1.6 !important; overflow-x: auto; overflow-y: auto; text-align: left; font-weight: normal; font-family: monaco, monospace; float: none; width: auto; -webkit-border-top-right-radius: 3px 3px; -webkit-border-top-left-radius: 3px 3px; -webkit-border-bottom-left-radius: 3px 3px; -webkit-border-bottom-right-radius: 3px 3px; ">
$(&quot;#friendSelectionInboxBox&quot;).autoComplete(emails, {
           minChars:0,
           width:310,
           matchContains:true,
           autoFill: false,
           formatItem: function (row, i, max)&nbsp;{
              return i + &quot;/&quot; + max + &quot;: \&quot;&quot; + row.name + &quot;\&quot; [&quot; + row.to + &quot;]&quot;;
           },
           formatMatch: function(row, i, max)&nbsp;{
              return row.name + &quot; &quot; + row.to;
          },
          formatResult:function (row){
              return row.to;
         }});</pre>
<p><span style="font-size: medium; ">&nbsp;</span><code>&nbsp;</code></p>
<p>And that&#8217;s it. You should now have a working friend selector :)</p>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblarnee.com%2Fwp%2Fhow-to-create-a-facebook-friend-selector-using-jquery-and-php-or-grails-without-fbml%2F&amp;t=How%20to%20create%20a%20Facebook%20Friend%20Selector%20using%20jQuery%20and%20PHP%20or%20Grails%20%28without%20FBML%29" id="facebook_share_button_416" style="font-size:11px; line-height:13px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif; text-decoration:none; display: -moz-inline-block; display:inline-block; padding:1px 20px 0 5px; margin: 5px 0; height:15px; border:1px solid #d8dfea; color: #3B5998; background: #fff url(http://b.static.ak.fbcdn.net/images/share/facebook_share_icon.gif) no-repeat top right;">Share</a>
<script type="text/javascript">
var button = document.getElementById('facebook_share_link_416') || document.getElementById('facebook_share_icon_416') || document.getElementById('facebook_share_both_416') || document.getElementById('facebook_share_button_416');
if (button) {
	button.onclick = function(e) {
		var url = this.href.replace(/share\.php/, 'sharer.php');
		window.open(url,'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
	}

	if (button.id === 'facebook_share_button_416') {
		button.onmouseover = function(){
			this.style.color='#fff';
			this.style.borderColor = '#295582';
			this.style.backgroundColor = '#3b5998';
		}
		button.onmouseout = function(){
			this.style.color = '#3b5998';
			this.style.borderColor = '#d8dfea';
			this.style.backgroundColor = '#fff';
		}
	}
}
</script>


<p>Related posts:<ol><li><a href='http://blarnee.com/wp/anatomy-of-a-facebook-application/' rel='bookmark' title='Permanent Link: Creating a Facebook Application &#8211; a simple guide for PHP, JavaScript, Flex and Grails developers.'>Creating a Facebook Application &#8211; a simple guide for PHP, JavaScript, Flex and Grails developers.</a> <small>&nbsp;If you&#8217;re a web developer and you haven&#8217;t explored the...</small></li><li><a href='http://blarnee.com/wp/creating-a-facebook-application-a-guide-for-php-javascript-flex-and-grails-developers/' rel='bookmark' title='Permanent Link: Creating a Facebook Application &#8211; a guide for PHP, JavaScript, Flex and Grails developers'>Creating a Facebook Application &#8211; a guide for PHP, JavaScript, Flex and Grails developers</a> <small> If you’re a web developer and you haven’t explored...</small></li><li><a href='http://blarnee.com/wp/how-to-create-impressive-animations-in-jquery-with-animate/' rel='bookmark' title='Permanent Link: How to create impressive animations in jQuery with .animate()'>How to create impressive animations in jQuery with .animate()</a> <small> I&#8217;ve been asked many times over the past month...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blarnee.com/wp/how-to-create-a-facebook-friend-selector-using-jquery-and-php-or-grails-without-fbml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
