<?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>.larre &#187; platform</title>
	<atom:link href="http://www.larre.com/tag/platform/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.larre.com</link>
	<description>technology, innovation and media</description>
	<lastBuildDate>Sat, 12 Nov 2011 20:23:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Building a Facebook Application in 15 minutes</title>
		<link>http://www.larre.com/2007/10/10/building-a-facebook-application-in-15-minutes/</link>
		<comments>http://www.larre.com/2007/10/10/building-a-facebook-application-in-15-minutes/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 09:29:07 +0000</pubDate>
		<dc:creator>larre</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[platform]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://larre.wordpress.com/2007/10/10/building-a-facebook-application-in-15-minutes/</guid>
		<description><![CDATA[So, after fowa and 90k+ developers in mind, I just had to go ahead and implement a Facebook application. Here is the code and how I implemented it. See also: Reflections after having implemented Facebook Connect and Google Friend Connect on my blog First of all my goal was to use an existing web application, write a facebook integration module that communicates with the Facebook APIs, extracting some information/data and presenting them inside the existing web application. The web application I used is based on a j2ee framework (jsp, java). The architecture is much like Struts The first thing to do was to get the Developer Application to my existing Facebook account. Then I had to download the Client Library. I choosed the Java Library since my development environment was Java. When I extracted the Client Library, only the source files where included. So what I had to do first (besides looking into the source code), was to compile the java-files. I actually wrote an ant-task for this purpose, but a more easier way is just to use javac without using ant-framework. The next step was to take the output from the compile process and put it into an archived [...]]]></description>
			<content:encoded><![CDATA[<p>So, after <a href="http://www.larre.com/2007/10/09/future-of-web-apps/">fowa</a> and 90k+ developers in mind, I just had to go ahead and implement a Facebook application. Here is the code and how I implemented it.</p>
<p><strong>See also: <a href="http://www.larre.com/2008/12/18/reflections-after-having-implemented-facebook-connect-and-google-friend-connect-on-my-blog/">Reflections after having implemented Facebook Connect and Google Friend Connect on my blog</a></strong></p>
<p>First of all my goal was to use an existing web application, write a facebook integration module that communicates with the Facebook APIs, extracting some information/data and presenting them inside the existing web application. The web application I used is based on a j2ee framework (jsp, java). The architecture is much like <a href="http://struts.apache.org">Struts</a> The first thing to do was to <a href="http://developers.facebook.com/get_started.php">get the Developer Application</a> to my existing Facebook account. Then I had to download the <a href="http://developers.facebook.com/resources.php">Client Library</a>. I choosed the Java Library since my development environment was Java. When I extracted the Client Library, only the source files where included. So what I had to do first (besides looking into the source code), was to compile the java-files. I actually wrote an ant-task for this purpose, but a more easier way is just to use javac without using ant-framework. The next step was to take the output from the compile process and put it into an archived file (.jar). This is not necessary but I like to do it this way and the facebook.jar file I now had is easily dropped into my existing web application library. In my Facebook profile I had to create (set up) a new application. This is done by clicking the developer application that was installed earlier. Its some steps including getting a key (API key and secret key) that I used in my java-code but this process is straight forward. [% oiopub-banner-4-right %]</p>
<p align="left">Ok, now lets start the coding process. Here is the java code controlling the session and authentication:</p>
<p align="left"><em>String apiKey = &#8220;something&#8221;;<br />
String secretKey = &#8220;something&#8221;; </em></p>
<p align="left"><em>FacebookRestClient frc = null;<br />
HttpSession session = request.getSession();<br />
String sessionKey = (String) session.getAttribute(&#8220;facebookSession&#8221;);<br />
String token = request.getParameter(&#8220;auth_token&#8221;);</em></p>
<p align="left"><em>try {</em></p>
<p align="left"><em>if (sessionKey != null &amp;&amp; sessionKey.length() &gt; 0) {</em></p>
<p align="left"><em>frc = new FacebookRestClient(apiKey, secretKey, sessionKey);<br />
this.doTheThing(request, response, frc);<br />
} else if (token != null) {<br />
frc = new FacebookRestClient(apiKey, secretKey);<br />
session.setAttribute(&#8220;facebookSession&#8221;, sessionKey);<br />
sessionKey = frc.auth_getSession(token);<br />
session.setAttribute(&#8220;facebookSession&#8221;, sessionKey);<br />
this.doTheThing(request, response, frc);<br />
</em></p>
<p align="left"><em>} else {<br />
response.sendRedirect(&#8220;http://www.facebook.com/login.php?api_key=&#8221; + apiKey + &#8220;&amp;v=1.0&#8243;);<br />
}<br />
} catch (FacebookException fe) {<br />
} catch (IOException ioe) {<br />
&#8230;</em></p>
<p align="left">The <em>doTheThing</em> method is extracting the information and looks like this:</p>
<p align="left"><em>int myid = frc.users_getLoggedInUser();<br />
EnumSet&lt;ProfileField&gt; fields = EnumSet.of(com.facebook.api.ProfileField.NAME, com.facebook.api.ProfileField.PIC, com.facebook.api.ProfileField.PIC_BIG, com.facebook.api.ProfileField.PIC_SMALL);<br />
Collection&lt;Integer&gt; users = new ArrayList();<br />
users.add(myid);</em></p>
<p><em>// Get my information<br />
Document d = frc.users_getInfo(users, fields);<br />
String myname = d.getElementsByTagName(&#8220;name&#8221;).item(0).getTextContent();<br />
String mypicture = d.getElementsByTagName(&#8220;pic&#8221;).item(0).getTextContent();</em></p>
<p><em>// Get my friends id<br />
Document d2 = frc.friends_get();<br />
String s = d2.toString();<br />
NodeList userIDNodes = d2.getElementsByTagName(&#8220;uid&#8221;);<br />
int fcount = userIDNodes.getLength();</em></p>
<p><em>Collection&lt;Integer&gt; friends = new ArrayList&lt;Integer&gt;();<br />
for (int i = 0; i &lt; fcount; i++) {<br />
Node node = userIDNodes.item(i);<br />
String idText = node.getTextContent();<br />
Integer id = Integer.valueOf(idText);<br />
friends.add(id);<br />
}</em></p>
<p><em>List l = new ArrayList();<br />
Map m = new HashMap();<br />
Document d3 = frc.users_getInfo(friends, fields);</em></p>
<p>// Get my friends information<br />
for (int j = 0; j &lt; fcount; j++) {<br />
String name2 = d3.getElementsByTagName(&#8220;name&#8221;).item(j).getTextContent();<br />
String picture2 = d3.getElementsByTagName(&#8220;pic&#8221;).item(j).getTextContent();<br />
String picture3 = d3.getElementsByTagName(&#8220;pic_small&#8221;).item(j).getTextContent();<br />
String picture4 = d3.getElementsByTagName(&#8220;pic_big&#8221;).item(j).getTextContent();</p>
<p><em>m.put(&#8220;name&#8221;, name2);<br />
m.put(&#8220;picture&#8221;, picture2);<br />
m.put(&#8220;picture_small&#8221;, picture3);<br />
m.put(&#8220;picture_big&#8221;, picture4);</em></p>
<p><em>l .add(m);<br />
m = new HashMap();</em></p>
<p><em>}<br />
request.setAttribute(&#8220;friends&#8221;, l);<br />
request.setAttribute(&#8220;myname&#8221;, myname);<br />
request.setAttribute(&#8220;mypicture&#8221;, mypicture);<br />
request.setAttribute(&#8220;numFriends&#8221;, new Integer(fcount));</em></p>
<p align="left">
<p align="left">So all the information from Facebook is now added to the request and can be displayed in a JSP. The code above is not very elegant and is not optimized(!). Its just a pice of code done after half an hour of work and my goal was to implement an integration module for testing purpose.</p>
<p>Hope this blog post can help others looking for hints when getting started with Facebook application development/integration</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-9866489500407536";
/* 468x60, opprettet 05.05.10 */
google_ad_slot = "1189263368";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larre.com/2007/10/10/building-a-facebook-application-in-15-minutes/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/5 queries in 0.015 seconds using disk: basic
Object Caching 331/331 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: static.larre.com

Served from: www.larre.com @ 2012-02-04 21:45:23 -->
