<?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>foomonger&#039;s blog &#187; remoting test client</title>
	<atom:link href="http://blog.foomonger.com/tag/remoting-test-client/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.foomonger.com</link>
	<description>Tips and Musings on Software Development, Flash, and Flex</description>
	<lastBuildDate>Wed, 14 Jul 2010 20:18:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google App Engine, Django, Flex, and Facebook</title>
		<link>http://blog.foomonger.com/2009/10/08/google-app-engine-django-flex-and-facebook/</link>
		<comments>http://blog.foomonger.com/2009/10/08/google-app-engine-django-flex-and-facebook/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 17:39:53 +0000</pubDate>
		<dc:creator>Sam Ahn</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[pyamf]]></category>
		<category><![CDATA[pyfacebook]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[remoting test client]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.foomonger.com/?p=12</guid>
		<description><![CDATA[RPSConquest was my first Google App Engine/Django/Flex/Facebook application. It's a turn-based rock-paper-scissors game played within Facebook. I built it to learn a variety of technologies and to see how well those technologies worked together. I was particularly interested in using Google App Engine and learning Python. In this post I'll elaborate on the technologies used, discuss [...]]]></description>
			<content:encoded><![CDATA[<p><a title="RPSConquest" href="http://apps.facebook.com/rpsconquest" target="_blank"><strong>RPSConquest</strong></a> was my first Google App Engine/Django/Flex/Facebook application. It's a turn-based rock-paper-scissors game played within Facebook. I built it to learn a variety of technologies and to see how well those technologies worked together. I was particularly interested in using Google App Engine and learning Python. In this post I'll elaborate on the technologies used, discuss curveballs I faced, and share some conclusions.</p>
<h2>Technologies:</h2>
<ul>
<li>Back-end:
<ul>
<li><a title="Google App Engine" href="http://code.google.com/appengine/" target="_blank">Google App Engine</a> (SDK 1.2.4)</li>
<li><a title="Python" href="http://www.python.org/" target="_blank">Python</a> (2.5.4)</li>
<li><a title="Django" href="http://www.djangoproject.com/" target="_blank">Django</a> (1.0.2)</li>
<li><a title="Google App Engine Helper for Django" href="http://code.google.com/p/google-app-engine-django/" target="_blank">Google App Engine Helper for Django</a> (revision 90)</li>
<li><a title="PyAMF" href="http://www.pyamf.org/" target="_blank">PyAMF</a> (0.5)
<ul>
<li><a title="PyAMF Test Client" href="http://blog.foomonger.com/pub/2009/10/08/google-app-engine-django-flex-and-facebook/pyamf_test_client.zip" target="_blank">PyAMF Test Client</a> (Slightly modified from the <a title="Original PyAMF Test Client" href="http://pyamf.org/attachment/ticket/508/client.py" target="_blank">original Test Client</a>)</li>
</ul>
</li>
<li><a title="Pyfacebook" href="http://github.com/sciyoshi/pyfacebook/" target="_blank">Pyfacebook</a> (0.1)</li>
</ul>
</li>
<li>Front-end:
<ul>
<li><a title="Flex" href="http://www.adobe.com/products/flex/" target="_blank">Flex</a> (3.3.0)</li>
<li><a title="Swiz Framework" href="http://code.google.com/p/swizframework/" target="_blank">Swiz Framework</a></li>
<li><a title="Facebook ActionScript Library" href="http://code.google.com/p/facebook-actionscript-api/" target="_blank">Facebook ActionScript Library</a></li>
</ul>
</li>
<li>Development Environment
<ul>
<li>Windows XP</li>
<li><a title="Eclipse" href="http://www.eclipse.org/" target="_blank">Eclipse</a>
<ul>
<li><a title="Flash Builder 4" href="http://labs.adobe.com/technologies/flashbuilder4/" target="_blank">Flash Builder 4 Plugin</a></li>
<li><a title="Pydev" href="http://pydev.org/" target="_blank">Pydev</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Flex has been my primary technology over the past couple years, and I wanted to build a Facebook game with it. I'm addicted to the Swiz Framework so I continued to use that (instead of Cairngorm). The app required a Flex Facebook-Friend-Selector component so I also needed the Facebook ActionScript Library for the FqlQuery command.</p>
<p>I planned to build an AMF service layer for the Flex app and almost went a LAMP/Zend setup on my personal web server. I was introduced to Google App Engine by a colleague and quickly went with it because of the automatic scalability and free quota.</p>
<p>App Engine currently supports Java and Python, and I went with Python because the Django framework sounded really interesting. Using the Google App Engine Helper for Django almost seemed like a must for a newbie like me.</p>
<p>There were a couple AMF libraries for Python, and I first tried <a title="DjangoAMF" href="http://djangoamf.sourceforge.jp/index.php?DjangoAMF_en" target="_blank">DjangoAMF</a> but quickly found it to be unusable for my Flex 3 app. I ended up using PyAMF which worked out really well. I wanted to write unit tests (which Django is great for) and found that I needed a test client for the remoting classes. I founded one on a random <a title="PyAMF Test Client Blog Post" href="http://swag.dk/blog/2009/04/21/django-compatible-pyamf-test-client/" target="_blank">blog post</a> and added it to my PyAMF files (with some minor modifications). With the remoting test client and the Django test client I was able to write and debug unit tests for all my AMF services.</p>
<p>My app needed to notify Facebook users and post messages on walls. Instead of doing this on the client-side, I did this in Python with Pyfacebook.</p>
<p>Instead of using the standalone Flex Builder, I used Eclipse with the Flash Builder 4 and Pydev plugins for development environment. I was able to  locally debug both Flex and Python code all while running the app within Facebook (thanks to <a href="http://www.google.com/search?hl=en&amp;q=facebook+%22port+forwarding%22+%22local+development%22&amp;aq=f&amp;oq=&amp;aqi=" target="_blank">port-forwarding</a>).</p>
<h2>Curveballs</h2>
<h3><strong>Version Compatibility</strong></h3>
<p>Though it was documented, I still stumbled with the version compatibility of Google App Engine, Python, and Django. Be sure to double-check what works with what in the latest documentation.</p>
<h3><strong>Locally Running the Python Server to be Available through Facebook</strong></h3>
<p>For local development I created a development Facebook application which pointed to my machine's IP address using port forwarding and <a href="http://dlinkddns.com" target="_blank">dlinkddns.com</a>. What I didn't understand until I read the <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/" target="_blank">docs</a> more carefully is that when I ran the development Python server using "manage.py", it defaulted to the <span style="font-family: Verdana, sans-serif; line-height: 16px; font-size: 12px; ">IP address 127.0.0.1 (on port 8000) which prevented Facebook from being allowed to hit the server even though it could hit my machine. I ended up using "<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; font-size: 13px; ">manage.py runserver 0.0.0.0:8000" which allowed Facebook to hit the development server.</span></span></p>
<h3><strong>Google App Engine Datastore is not a Relational Database</strong></h3>
<p>Before I decided to go with App Engine I had sketched out my model to create tables in a MySQL database. I had about a half-dozen tables which in Django directly correlates to a half-dozen model classes. As I was developing the business logic I learned that the App Engine datastore is not a relational database. I couldn't do joins. That forced me to significantly refactor and basically de-normalize my model down to 2 classes.</p>
<p>These links helped me understand what was going on:</p>
<ul>
<li><a href="http://tech.boradev.com/?p=38" target="_blank">http://tech.boradev.com/?p=38</a></li>
<li><a href="http://code.djangoproject.com/wiki/AppEngine" target="_blank">http://code.djangoproject.com/wiki/AppEngine</a></li>
</ul>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 703px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">http://tech.boradev.com/?p=38</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 703px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>http://code.djangoproject.com/wiki/AppEngine</div>
<h3><strong>Mocking or Lack Thereof</strong></h3>
<p>The service code uses Pyfacebook and requests data from Facebook. I didn't want that code to run during unit tests largely because it wouldn't have the proper session keys. I briefly looked into mocking some of the Pyfacebook code for the unit test but without success at first pass. I cheated using a settings flag so that code wouldn't be run during unit tests to just get the features done for now. I hope to properly learn mocking in Python in the future.</p>
<h3><strong>Facebook Session Keys and AMF</strong></h3>
<p>From my understanding normally HTTP requests from a Facebook application would contain a bunch of Facebook data such as session keys. With AMF service calls, those HTTP requests do not have that data so the facebook object that the Pyfacebook middleware creates doesn't have some values set such as the session key. And that session key is needed for some of the API calls I was using. I ended up not using the middleware according to <a href="http://lethain.com/entry/2007/nov/30/using-pyfacebook-without-facebook-middleware/" target="_blank">this post</a>, manually created the facebook object, and manually set the session key which I parsed out from authentication data sent to the service methods. The authentication data was based on the Facebook <a href="http://wiki.developers.facebook.com/index.php/Fb:swf#Notes" target="_blank">fb:swf notes</a> which allows you to verify that the swf was loaded from your Facebook app.</p>
<h3><strong>Facebook One-line Story Publishing</strong></h3>
<p>I was very confused about how my application should post messages (stories) to Facebook users' walls and the permissions it required. For now I wanted to avoid explicitly asking for elaborate permissions. Posting one-line stories  seemed like it didn't require the "publish_stream" extended permission. I ended up making sure the user was logged in, that the app was added to the user, and using the <a href="http://wiki.developers.facebook.com/index.php/Feed.publishUserAction" target="_blank">feed.publishUserAction</a> API. I didn't use the recommended <a href="http://wiki.developers.facebook.com/index.php/Stream.publish" target="_blank">stream.publish</a> API because it appeared to only publish "short stories" which required extended permissions.</p>
<h2>Conclusions</h2>
<p>I loved using Python and Django. I found Python to be a very friendly yet powerful language and Django to be a very efficient yet powerful framework. It let me quickly build up a tested AMF service layer. I'm very curious about the future of Django in commercial projects.</p>
<p>I think using Google App Engine, Django, and Flex is a great way to quickly build scalable Facebook applications. You definitely have to get used to programming for App Engine though. If you're not afraid to commit to coding specifically for App Engine then it seems like a great solution. I think development speed and scalability are key aspects in social media application development. This combination of technologies seems to address those aspects very well.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.foomonger.com%2F2009%2F10%2F08%2Fgoogle-app-engine-django-flex-and-facebook%2F&amp;linkname=Google%20App%20Engine%2C%20Django%2C%20Flex%2C%20and%20Facebook"><img src="http://blog.foomonger.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.foomonger.com/2009/10/08/google-app-engine-django-flex-and-facebook/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
