<?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>Emanuele Feronato &#187; Facebook</title>
	<atom:link href="http://www.emanueleferonato.com/category/facebook/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:28:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Develop Flash Facebook applications with Facebook Graph API Development with Flash</title>
		<link>http://www.emanueleferonato.com/2011/01/20/develop-flash-facebook-applications-with-facebook-graph-api-development-with-flash/</link>
		<comments>http://www.emanueleferonato.com/2011/01/20/develop-flash-facebook-applications-with-facebook-graph-api-development-with-flash/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 21:51:35 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3707</guid>
		<description><![CDATA[The latest result of my collaboration with Packt Publishing is Facebook Graph API Development with Flash by Michael James Williams, who also owns a blog about Flash game developing. Michael is an excellent writer and I was pleased to be the reviewer of this book. Yes, it&#8217;s me!! I&#8217;ve carefully read the book page by [...]]]></description>
			<content:encoded><![CDATA[<p>The latest result of my collaboration with Packt Publishing is <strong><a target = "_blank" href="http://link.packtpub.com/v58Wnp">Facebook Graph API Development with Flash</a></strong> by Michael James Williams, who also owns a <a href="http://gamedev.michaeljameswilliams.com/" target = "_blank">blog about Flash game developing</a>.</p>
<p><a target = "_blank" href="http://link.packtpub.com/v58Wnp"><img src="/wp-content/uploads/2011/01/graphapibook.jpg" /></a></p>
<p>Michael is an excellent writer and I was pleased to be the reviewer of this book.<span id="more-3707"></span></p>
<p><a target = "_blank" href="http://link.packtpub.com/v58Wnp"><img src="/wp-content/uploads/2011/01/graphapibook2.jpg" /></a></p>
<p>Yes, it&#8217;s me!! I&#8217;ve carefully read the book page by page, image by image, and I have to say it&#8217;s a great resource both for developers trying to make Flash Facebook applications and for <strong>everyone looking for a guide on the Facebook Graph API</strong>. Guaranteed by the reviewer :)</p>
<p>While some tutorials taken from the book will come soon (I am polishing the book I am writing during these days and I have thousands of ideas to show you once it will be on the shelves), let me show you what you&#8217;ll learn reading this book:</p>
<p>* Make your AS3 projects more social and personalise them for your users by adding Facebook integration<br />
* Grab information directly from Facebook into your applications by using Facebook&#8217;s Graph API<br />
* Securely authenticate your users with OAuth 2.0 to log them into Facebook<br />
* Access information about your users and their friends directly from Facebook – no need to make them type it all in again<br />
* Upload photographs, add wall posts, and create events through AS3<br />
* Search on Facebook&#8217;s databases with the powerful Facebook Query Language<br />
* Build an AS3 Facebook SDK that you can drop into any AS3 project to add Facebook integration<br />
* Easily access both public and private Facebook data from the surface of a graph </p>
<p>If you&#8217;re looking for a book to start developing Flash Facebook applications, <a target = "_blank" href="http://link.packtpub.com/v58Wnp">Facebook Graph API Development with Flash</a> is your book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/01/20/develop-flash-facebook-applications-with-facebook-graph-api-development-with-flash/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Create a Facebook application like &#8220;Friend interview&#8221; &#8211; Step 3</title>
		<link>http://www.emanueleferonato.com/2010/11/24/create-a-facebook-application-like-friend-interview-step-3/</link>
		<comments>http://www.emanueleferonato.com/2010/11/24/create-a-facebook-application-like-friend-interview-step-3/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 17:35:58 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3527</guid>
		<description><![CDATA[Here we go with the 3rd step. In this tutorial you will learn how to publish a full featured feed post to your friends&#8217; wall, and to handle &#8220;umlauts&#8221; characters like &#8220;äöü&#8221; for the pleasure of our German readers, and for every user who has friends whose names contain special characters. This is the kind [...]]]></description>
			<content:encoded><![CDATA[<p>Here we go with the 3rd step. In this tutorial you will learn how to publish a full featured feed post to your friends&#8217; wall, and to handle &#8220;umlauts&#8221; characters like &#8220;äöü&#8221; for the pleasure of our German readers, and for every user who has friends whose names contain special characters.</p>
<p>This is the kind of feed you are going to publish:</p>
<p><img src="/wp-content/uploads/2010/11/fbfeed02.jpg" /></p>
<p>And this is the link of the application, just in case you want to have a look: <a href="http://apps.facebook.com/about_you_game/" target = "_blank">About you Facebook application</a></p>
<p>The code is almost similar to the one we used in <a href="http://www.emanueleferonato.com/2010/10/28/create-a-facebook-application-like-friend-interview-step-2/">step 2</a>:<span id="more-3527"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'appId'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'157934074246374'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'secret'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'dontstealmysecretkey'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cookie'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span><span style="color: #0000ff;">'domain'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'gamesalsa.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'canvas'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fbconnect'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'req_perms'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'publish_stream'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'next'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'http://apps.facebook.com/about_you_game/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cancel_url'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'http://apps.facebook.com/about_you_game/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Redirecting to permission request...&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;top.location.href = '<span style="color: #006699; font-weight: bold;">$url</span>';&lt;/script&gt;&quot;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>to_do<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;Answer and publish&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$ch</span><span style="color: #339933;">=</span><span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;https://graph.facebook.com/<span style="color: #006699; font-weight: bold;">$_POST[user]</span>/feed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;access_token=<span style="color: #006699; font-weight: bold;">$session[access_token]</span>&amp;message=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;just answered a question about you:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;link=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://apps.facebook.com/about_you_game/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;picture=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.gamesalsa.com/aboutyou/about_you_icon.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;name=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Do you think <span style="color: #006699; font-weight: bold;">$_POST[name]</span> likes this app ?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;caption=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;and the answer is...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;description=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>answer<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;actions=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #000099; font-weight: bold;">\&quot;</span>name<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>Play now<span style="color: #000099; font-weight: bold;">\&quot;</span>, <span style="color: #000099; font-weight: bold;">\&quot;</span>link<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>http://apps.facebook.com/about_you_game/<span style="color: #000099; font-weight: bold;">\&quot;</span>}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$friends</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'me/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$number_of_friends</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$random</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$number_of_friends</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friend_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$random</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friend_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$random</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://graph.facebook.com/<span style="color: #006699; font-weight: bold;">$friend_id</span>/picture?type=large&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&nbsp;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=utf-8&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div style = &quot;width:513px;background-color:#edeff4;background-image:url('<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$img</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>');background-repeat:no-repeat;padding:5px 5px 5px 210px;font:normal 16px verdana&quot;&gt;
		Do you think &lt;span style = &quot;color:red;fnt-weight:bold&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$friend_name</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt; likes this app?
		&lt;form method = &quot;post&quot; style =&quot;margin-top:20px&quot;&gt;
		     &lt;textarea name = &quot;answer&quot; style = &quot;border:1px solid #bdc7d8;width:100%;height:100px;font:normal 15px verdana&quot;&gt;&lt;/textarea&gt;
		     &lt;input type = &quot;hidden&quot; name = &quot;user&quot; value = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$friend_id</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
		     &lt;input type = &quot;hidden&quot; name = &quot;name&quot; value = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$friend_name</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
		     &lt;input type =&quot;submit&quot; value = &quot;Answer and publish&quot; name =&quot;to_do&quot;/&gt; &lt;input type =&quot;submit&quot; value = &quot;Just answer&quot; name =&quot;to_do&quot;/&gt;
		&lt;/form&gt;
	&lt;/div&gt;
&nbsp;
	&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
	google_ad_client = &quot;pub-2062493463858889&quot;;
	/* about you */
	google_ad_slot = &quot;0401513269&quot;;
	google_ad_width = 728;
	google_ad_height = 90;
	//--&gt;
	&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;
	src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
	&lt;/script&gt;
&nbsp;
&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Using proper html tags such as <code>http-equiv</code> at <strong>line 38</strong> allow us to properly render special characters, while the key of this post is <strong>line 20</strong>, where we pass a lot more information than in <a href="http://www.emanueleferonato.com/2010/10/28/create-a-facebook-application-like-friend-interview-step-2/">step 2</a>.</p>
<p>Let&#8217;s see it in detail:</p>
<p><strong>access_token</strong>: it&#8217;s the access token required to publish on friends&#8217; wall. Its value must be</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$session</span><span style="color: #009900;">&#91;</span>access_token<span style="color: #009900;">&#93;</span></pre></div></div>

<p><strong>message</strong>: it&#8217;s the message which will appear next to your name. I used</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;just answered a question about you:&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>because I wanted my friend to see &#8220;Emanuele Feronato just answered a question about you:&#8221;. I also used <code>urlencode</code> although it&#8217;s useless in this case, just not to forget to encode the string should I change it in the near future with another string with some special characters.</p>
<p><strong>picture</strong>: the absolute URL of the picture to display on the left of your post.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.gamesalsa.com/aboutyou/about_you_icon.png&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>name</strong>: it&#8217;s the name of the link you are publishing in the feed. This is where we will place the question.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Do you think <span style="color: #006699; font-weight: bold;">$_POST[name]</span> likes this app ?&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>link</strong>: it&#8217;s the link attached to the picture and the name. You may want to use the URL of the application itself.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://apps.facebook.com/about_you_game/&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>caption</strong>: the caption of the link, placed just under the link itself. Don&#8217;t write anything important here as it won&#8217;t be noticed that much since the blue color of the link grabs almost all attention. Perfect to write something like &#8220;and the answer is&#8230;&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;and the answer is...&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>description</strong>: it&#8217;s the description of the link and it&#8217;s the longest text you can enter. We&#8217;ll place the answer there.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>answer<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><strong>actions</strong>: you can also add a custom action to the action footer of the post (where you can find &#8220;Like&#8221;, &#8220;Comment&#8221;, and so on). Actions should be added as a JSON list containing &#8220;name&#8221; and &#8220;link&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{<span style="color: #000099; font-weight: bold;">\&quot;</span>name<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>Play now<span style="color: #000099; font-weight: bold;">\&quot;</span>, <span style="color: #000099; font-weight: bold;">\&quot;</span>link<span style="color: #000099; font-weight: bold;">\&quot;</span>: <span style="color: #000099; font-weight: bold;">\&quot;</span>http://apps.facebook.com/about_you_game/<span style="color: #000099; font-weight: bold;">\&quot;</span>}&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>And here you, go, have a try with the application: <a href="http://apps.facebook.com/about_you_game/" target = "_blank">About you Facebook application</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/11/24/create-a-facebook-application-like-friend-interview-step-3/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Create a Facebook application like &#8220;Friend interview&#8221; &#8211; Step 2</title>
		<link>http://www.emanueleferonato.com/2010/10/28/create-a-facebook-application-like-friend-interview-step-2/</link>
		<comments>http://www.emanueleferonato.com/2010/10/28/create-a-facebook-application-like-friend-interview-step-2/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 08:55:02 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3450</guid>
		<description><![CDATA[In step 1 you learned how to authenticate and select a random friend of yours. In this second part you will learn how to get more information about your friends and how to post the answer on their wall. This is what you will get: and once you hit &#8220;Answer and publish&#8221; you will post [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.emanueleferonato.com/2010/10/20/create-a-facebook-application-like-friend-interview/">step 1</a> you learned how to authenticate and select a random friend of yours.</p>
<p>In this second part you will learn how to get more information about your friends and how to post the answer on their wall.</p>
<p>This is what you will get:</p>
<p><img src="/wp-content/uploads/2010/10/friends01.jpg" /></p>
<p>and once you hit &#8220;Answer and publish&#8221; you will post on your friend&#8217;s wall this way:</p>
<p><img src="/wp-content/uploads/2010/10/friends02.jpg" /></p>
<p>You need to know how <a href="http://php.net/manual/en/book.curl.php" target = "_blank">cURL</a> works. I may consider publishing a tutorial about cURL if I have enough requests.</p>
<p>Let&#8217;s  jump straight to the code:<span id="more-3450"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'appId'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'157934074246374'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'secret'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'onceiwasapornsuperstar'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cookie'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span><span style="color: #0000ff;">'domain'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'gamesalsa.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'canvas'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fbconnect'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'req_perms'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'publish_stream'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'next'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'http://apps.facebook.com/about_you_game/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cancel_url'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'http://apps.facebook.com/about_you_game/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Redirecting to permission request...&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;top.location.href = '<span style="color: #006699; font-weight: bold;">$url</span>';&lt;/script&gt;&quot;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>to_do<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;Answer and publish&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$ch</span><span style="color: #339933;">=</span><span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;https://graph.facebook.com/<span style="color: #006699; font-weight: bold;">$_POST[user]</span>/feed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;access_token=<span style="color: #006699; font-weight: bold;">$session[access_token]</span>&amp;message=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Do you think <span style="color: #006699; font-weight: bold;">$_POST[name]</span> likes this app ?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;link=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://apps.facebook.com/about_you_game/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;name=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>answer<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$friends</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'me/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$number_of_friends</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$random</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$number_of_friends</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friend_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$random</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friend_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$random</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://graph.facebook.com/<span style="color: #006699; font-weight: bold;">$friend_id</span>/picture?type=large&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&nbsp;
&lt;div style = &quot;width:513px;background-color:#edeff4;background-image:url('<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$img</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>');background-repeat:no-repeat;padding:5px 5px 5px 210px;font:normal 16px verdana&quot;&gt;
Do you think &lt;span style = &quot;color:red;fnt-weight:bold&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$friend_name</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt; likes this app?
&lt;form method = &quot;post&quot; style =&quot;margin-top:20px&quot;&gt;
     &lt;textarea name = &quot;answer&quot; style = &quot;border:1px solid #bdc7d8;width:100%;height:100px;font:normal 15px verdana&quot;&gt;&lt;/textarea&gt;
     &lt;input type = &quot;hidden&quot; name = &quot;user&quot; value = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$friend_id</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
     &lt;input type = &quot;hidden&quot; name = &quot;name&quot; value = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$friend_name</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
     &lt;input type =&quot;submit&quot; value = &quot;Answer and publish&quot; name =&quot;to_do&quot;/&gt; &lt;input type =&quot;submit&quot; value = &quot;Just answer&quot; name =&quot;to_do&quot;/&gt;
&lt;/form&gt;
&lt;/div&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Obviously I won&#8217;t comment HTML, so let&#8217;s dive into php exploring the new lines not already explained in <a href="http://www.emanueleferonato.com/2010/10/20/create-a-facebook-application-like-friend-interview/">step 1</a>.</p>
<p><strong>Line 10</strong>: getting the login url with some new parameters:</p>
<p><code>next</code>: the url to go to after a successful login<br />
<code>cancel_url</code>: the url to go to after the user cancels<br />
<code>req_perms</code>: comma separated list of requested extended perms</p>
<p>I am asking for <code>publish_stream</code> permission. It enables your application to post content, comments, and likes to a user&#8217;s stream and to the streams of the user&#8217;s friends. That&#8217;s what I need to publish something on my friends&#8217; wall.</p>
<p>You can find the full docs about permissions at <a href="http://developers.facebook.com/docs/authentication/permissions" target = "_blank">this official page</a>.</p>
<p><strong>Line 15</strong>: I am about to publish the answer about a random friend if the user clicked on &#8220;Answer and publish&#8221; button (<strong>line 43</strong>)</p>
<p><strong>Line 16</strong>: initializing a cURL session</p>
<p><strong>Line 17</strong>: setting the URL where to send the cURL request</p>
<p><strong>Line 18</strong>: saving the result of the cURL session in a string</p>
<p><strong>Line 19</strong>: setting cURL method to <code>POST</code></p>
<p><strong>Line 20</strong>: the core of the script: the variables to be passed in <code>POST</code>.</p>
<p><code>access_token</code>: the authorization token.<br />
<code>message</code>: the URL encoded message (&#8220;Do you think xxx likes this app?&#8221;)<br />
<code>link</code>: the link to the application<br />
<code>name</code>: the answer to the question</p>
<p><strong>Line 21</strong>: executing the cURL session</p>
<p><strong>Line 22</strong>: closing the cURL session</p>
<p>The big profile image on the left of the question can be obtained at <strong>line 29</strong>.</p>
<p>Test the application at <a href="http://apps.facebook.com/about_you_game/" target = "_blank">this page</a>.</p>
<p>Next time, generating and saving random questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/10/28/create-a-facebook-application-like-friend-interview-step-2/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Create a Facebook application like &#8220;Friend interview&#8221;</title>
		<link>http://www.emanueleferonato.com/2010/10/20/create-a-facebook-application-like-friend-interview/</link>
		<comments>http://www.emanueleferonato.com/2010/10/20/create-a-facebook-application-like-friend-interview/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 21:41:41 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3429</guid>
		<description><![CDATA[Do you know Friend Interview? It&#8217;s a Facebook application which asks a random question about a random friend of yours, and publish the result on his wall. I won&#8217;t publish a snapshot of such app since it&#8217;s full of rubbish and ads, but I am sure you know what I am talking about (and moreover [...]]]></description>
			<content:encoded><![CDATA[<p>Do you know <strong><a href="http://apps.facebook.com/friendinterview/" target = "_blank">Friend Interview</a></strong>?</p>
<p>It&#8217;s a Facebook application which asks a random question about a random friend of yours, and publish the result on his wall. I won&#8217;t publish a snapshot of such app since it&#8217;s full of rubbish and ads, but I am sure you know what I am talking about (and moreover there&#8217;s the link!).</p>
<p>You should know how to create a Facebook application, anyway I&#8217;ll post a recap here.</p>
<p>1) Go to <a href="http://www.facebook.com/developers/" target = "_blank">http://www.facebook.com/developers/</a> and click on &#8220;Set Up New Application&#8221;.</p>
<p><img src="/wp-content/uploads/2010/10/intw01.jpg" /></p>
<p>2) Give a name to your application. You can give it any name as long as it does not infringe copyrights, agree to terms and click on &#8220;Create Application&#8221;.</p>
<p><img src="/wp-content/uploads/2010/10/intw02.jpg" /></p>
<p>3) On &#8220;Facebook Integration&#8221; panel give it a Canvas Page name (this must be unique), and in &#8220;Canvas URL&#8221; write the path on the folder on your server which will contain the application itself, set &#8220;Canvas Type&#8221; as &#8220;IFrame&#8221; and &#8220;IFrame Size&#8221; to &#8220;Auto-resize&#8221;, then press &#8220;Save Changes&#8221; and at the moment you are ready to create your application.</p>
<p><img src="/wp-content/uploads/2010/10/intw03.jpg" /></p>
<p>4) Download the Facebook API from <a href="http://github.com/facebook/php-sdk/archives/v2.1.2">GitHub</a> and copy <code>facebook.php</code> in the folder you specified in the Canvas URL.</p>
<p>Now everything is ready to develop your application. In this first part, we will ask for permissions and choose one random friend.<span id="more-3429"></span></p>
<p>Create a new file called <code>index.php</code> with this code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'appId'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'157934074246374'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'secret'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'sorrythissecretkeywontwork'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cookie'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span><span style="color: #0000ff;">'domain'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'gamesalsa.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'canvas'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fbconnect'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Redirecting to permission request...&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;top.location.href = '<span style="color: #006699; font-weight: bold;">$url</span>';&lt;/script&gt;&quot;</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$friends</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'me/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$number_of_friends</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;You have <span style="color: #006699; font-weight: bold;">$number_of_friends</span> friends&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$random</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$number_of_friends</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;A random friend name: &lt;strong&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$random</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/strong&gt;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;A good question would be: do you think &lt;strong&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span>data<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$random</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/strong&gt; likes this app?&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Let&#8217;s see its meaning:</p>
<p><strong>Line 3</strong>: including the required library.</p>
<p><strong>Line 5</strong>: initializing the Facebook application. In the array you must pass the following elements:</p>
<p><code>appId</code>: the application ID<br />
<code>secret</code>: the application secret<br />
<code>cookie</code>: (optional) boolean true to enable cookie support<br />
<code>domain</code>: (optional) domain for the cookie<br />
<code>fileUpload</code>: (optional) boolean indicating if file uploads are enabled</p>
<p><strong>Line 7</strong>:  getting the session object. At this point, the script splits in two paths, according to $session value.</p>
<p><strong>$session is NULL (lines 9-13)</strong></p>
<p>If <code>$session</code> is <code>NULL</code>, we need to redirect to the login url to let the player allow the application use his personal information. The redirection is made with a simple javascript, using <code>getLoginUrl</code>.</p>
<p><strong>$session is not NULL (lines 14-21)</strong></p>
<p>In this case I put in <code>$friends</code> array an array with all friends names and Ids, then I randomly pick one of them and display its name and a possible question.</p>
<p>And that&#8217;s it, this is what you&#8217;ll get:</p>
<p><img src="/wp-content/uploads/2010/10/kirenia.png" /></p>
<p>You can test it by yourself here: <a href="http://apps.facebook.com/about_you_game/" target="_blank">http://apps.facebook.com/about_you_game/</a></p>
<p>Now you know how to pick a random friend. During next step you will be able to answer a question about him and post it on its wall.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/10/20/create-a-facebook-application-like-friend-interview/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>PHP Facebook Graph API &#8220;Hello World&#8221; application</title>
		<link>http://www.emanueleferonato.com/2010/09/17/php-facebook-graph-api-hello-world-application/</link>
		<comments>http://www.emanueleferonato.com/2010/09/17/php-facebook-graph-api-hello-world-application/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 23:12:47 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3332</guid>
		<description><![CDATA[While I am preparing a new tutorial about Facebook applications (and a php FB game, maybe HTML5 based), I notice there isn&#8217;t any &#8220;Hello World&#8221; application about Facebook applications using the new Graph API with just some PHP lines. If you don&#8217;t know what is the Graph API and don&#8217;t want to get an headache [...]]]></description>
			<content:encoded><![CDATA[<p>While I am preparing a new tutorial about Facebook applications (and a php FB game, maybe HTML5 based), I notice there isn&#8217;t any &#8220;Hello World&#8221; application about Facebook applications using the new Graph API with just some PHP lines.</p>
<p>If you don&#8217;t know what is the Graph API and don&#8217;t want to get an headache with strange words such as &#8220;access token&#8221;, ever mind&#8230; as said I&#8217;ll explain it in a few days. But if you are already messing with Graph API and Facebook and are looking for a really simple and working code, this is the post for you.</p>
<p>Try the application: <a href="http://apps.facebook.com/hello_worldz/" target = "_blank">Hello World</a>.</p>
<p>&#8230; and get the source code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'appId'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'150635898302665'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'secret'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'12345678901234567890123456789012'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'cookie'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span><span style="color: #0000ff;">'domain'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'gamemummy.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;Current session content&lt;/strong&gt;:&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
try<span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$me</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span> <span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;Graph data about me&lt;/strong&gt;:&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$me</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;strong&gt;Facebook exception&lt;/strong&gt;: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$e</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'canvas'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fbconnect'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h3&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>javascript:void(0)<span style="color: #000099; font-weight: bold;">\&quot;</span> onclick=<span style="color: #000099; font-weight: bold;">\&quot;</span>top.location.href = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Get access token&lt;/a&gt;&lt;/h3&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>&#8230; and don&#8217;t try to steal my secret key, it&#8217;s not real&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/09/17/php-facebook-graph-api-hello-world-application/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Horror Profile Facebook application source code released</title>
		<link>http://www.emanueleferonato.com/2009/12/04/horror-profile-facebook-application-source-code-released/</link>
		<comments>http://www.emanueleferonato.com/2009/12/04/horror-profile-facebook-application-source-code-released/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 09:23:57 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2027</guid>
		<description><![CDATA[Horror Profile is a Facebook application I developed a month ago. Now it&#8217;s time to release the source code. You will find some useful tips about dynamic image creation with php. If you are absolutely new to Facebook applications, I suggest you to read &#8220;Developing a Facebook Application for absolute beginners&#8221; posts 1, 2, 3, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://apps.facebook.com/horror_name/" target ="_blank"><strong>Horror Profile</strong></a> is a Facebook application <a href="http://www.emanueleferonato.com/2009/10/28/horror-profile-facebook-application/">I developed a month ago</a>.</p>
<p>Now it&#8217;s time to release  the source code. You will find some useful tips about dynamic image creation with php.</p>
<p>If you are absolutely new to Facebook applications, I suggest you to read &#8220;Developing a Facebook Application for absolute beginners&#8221; posts <a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">1</a>, <a href="http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/">2</a>, <a href="http://www.emanueleferonato.com/2009/09/30/developing-a-facebook-application-for-absolute-beginners-%E2%80%93-step-3/">3</a>, <a href="http://www.emanueleferonato.com/2009/10/07/developing-a-facebook-application-for-absolute-beginners-step-4/">4</a> and <a href="http://www.emanueleferonato.com/2009/10/09/developing-a-facebook-application-for-absolute-beginners-step-5/">5</a>.</p>
<p>The idea is simple: placing the profile picture in a mirror (that is a transparent PNG image) and writing the user first name as big as I can.<span id="more-2027"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this is the core function.</span>
<span style="color: #666666; font-style: italic;">// giving an user id, a text (user first name) and an url (path to the user profile picture)</span>
<span style="color: #666666; font-style: italic;">// creates the horror picture</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> create_pic<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// creation of a new image, the final one</span>
	<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// importing profile picture</span>
	<span style="color: #000088;">$profile</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// importing transparent mirror image</span>
	<span style="color: #000088;">$mirror</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mirror.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// retrieving profile picture size</span>
	<span style="color: #000088;">$sizes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$x_dim</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sizes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$y_dim</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sizes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// mirror transparency is 265x335, so I resize the profile picture</span>
	<span style="color: #666666; font-style: italic;">// to fit this size, keeping widht/height ratio</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x_dim</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">265</span> or <span style="color: #000088;">$y_dim</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">335</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$mult</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">265</span><span style="color: #339933;">/</span><span style="color: #000088;">$x_dim</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">335</span><span style="color: #339933;">/</span><span style="color: #000088;">$y_dim</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$final_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x_dim</span><span style="color: #339933;">*</span><span style="color: #000088;">$mult</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$final_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$y_dim</span><span style="color: #339933;">*</span><span style="color: #000088;">$mult</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pasting the resized profile picture on the final image</span>
	<span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$profile</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">250</span><span style="color: #339933;">-</span><span style="color: #000088;">$final_x</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">300</span><span style="color: #339933;">-</span><span style="color: #000088;">$final_y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$final_x</span><span style="color: #339933;">,</span><span style="color: #000088;">$final_y</span><span style="color: #339933;">,</span><span style="color: #000088;">$x_dim</span><span style="color: #339933;">,</span><span style="color: #000088;">$y_dim</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// pasting the mirror on the final image</span>
	<span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$mirror</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// creating some colors</span>
	<span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$shadow</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// this is the path of the font I am using</span>
	<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SF Gushing Meadow.ttf&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// starting at font size 0</span>
	<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// boolean variable to determine if the font fits on the picture</span>
	<span style="color: #000088;">$it_fits</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// increasing font zize by one unit until it won't fit anymore</span>
	<span style="color: #b1b100;">do</span><span style="color: #009900;">&#123;</span>
	     <span style="color: #000088;">$last_dim</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dim</span><span style="color: #339933;">;</span>
	     <span style="color: #000088;">$size</span><span style="color: #339933;">++;</span>
	     <span style="color: #000088;">$dim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imageftbbox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #000088;">$dim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	          <span style="color: #000088;">$it_fits</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	     <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$it_fits</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// adding the text</span>
	<span style="color: #000088;">$center</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">-</span><span style="color: #000088;">$last_dim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$last_dim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$center</span><span style="color: #339933;">,</span> <span style="color: #000088;">$last_dim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shadow</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$center</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$last_dim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// saving the image</span>
	<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;temp/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// freeing memory</span>
	<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$profile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mirror</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;script&gt;
     function grant() {
         document.setLocation(&quot;http://apps.facebook.com/horror_name/?pub=1&quot;);
     }
&lt;/script&gt;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$appapikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;xxxxx&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$appsecret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;xxxx&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$appapikey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$appsecret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$user_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">require_login</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$my_array</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users_getInfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;first_name,pic_big&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// getting user name and profile picture</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$my_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>first_name<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pic</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$my_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>pic_big<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// core function: creation of the horror picture</span>
create_pic<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #000088;">$pic</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$has_permission</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users_hasAppPermission</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;photo_upload&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$has_permission</span> and <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>pub<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$response_array</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">photos_upload</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;temp/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$user_id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.jpg&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Created with http://apps.facebook.com/horror_name/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;style&gt;
     <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;style.css&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/style&gt;
&nbsp;
&lt;h2&gt;Hello &lt;fb:name uid=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$user_id</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; useyou=&quot;false&quot; linked=&quot;false&quot; firstnameonly=&quot;true&quot;&gt;&lt;/fb:name&gt;, let's see how horrific is your profile:&lt;/h2&gt;
&nbsp;
&lt;div class = &quot;image&quot;&gt;&lt;img src = &quot;http://www.gamemummy.com/facebook/horror_name/temp/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$user_id</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>.jpg&quot; /&gt;&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$has_permission</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
     &lt;div class = &quot;publish&quot;&gt;&lt;fb:prompt-permission perms=&quot;photo_upload&quot; next_fbjs=&quot;grant()&quot;&gt;Scare your friends!! Publish this horrific photo on your profile!!&lt;/fb:prompt-permission&gt;&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>pub<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
     	&lt;div class = &quot;publish&quot;&gt;&lt;a href = &quot;http://apps.facebook.com/horror_name/?pub=1&quot;&gt;Scare your friends!! Publish this horrific photo on your profile!!&lt;/a&gt;&lt;/div&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;div class = &quot;publish&quot;&gt;PHOTO PUBLISHED&lt;/div&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div class = &quot;ad&quot;&gt;&lt;fb:iframe src = &quot;http://www.gamemummy.com/facebook/horror_name/ad.html&quot; width = &quot;728&quot; height = &quot;90&quot; frameborder = &quot;0&quot;&gt;&lt;/fb:iframe&gt;&lt;/div&gt;
&nbsp;
&lt;ul&gt;
	&lt;li&gt;Concept and coding by &lt;a href = &quot;http://emanueleferonato.com/&quot; target = &quot;_blank&quot;&gt;Emanuele Feronato&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Picture by &lt;a href = &quot;http://aliceindeadland.deviantart.com/&quot; target = &quot;_blank&quot;&gt;AliceinDeadLand&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>Hope you will make something decent out of it&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/12/04/horror-profile-facebook-application-source-code-released/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Creation of a Flash Facebook application using AMFPHP</title>
		<link>http://www.emanueleferonato.com/2009/11/17/creation-of-a-flash-facebook-application-using-amfphp/</link>
		<comments>http://www.emanueleferonato.com/2009/11/17/creation-of-a-flash-facebook-application-using-amfphp/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:29:05 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1966</guid>
		<description><![CDATA[Some days ago I showed you how to create a Flash Facebook application using the AS3 API. Now Yarden Refaeli from Rigel Games is sharing with us his experience in creating a Flash Facebook application using another technique. Let&#8217;s read it: &#171; Hello, my name is Yarden Refaeli and I have been flash programmer for [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago I showed you <a href="http://www.emanueleferonato.com/2009/11/04/creating-a-flash-facebook-application-with-the-facebook-actionscript-api/">how to create a Flash Facebook application using the AS3 API</a>.</p>
<p>Now <strong>Yarden Refaeli</strong> from <a href="http://www.rigelgames.com/" target="_blank"><strong>Rigel Games</strong></a> is sharing with us his experience in creating a Flash Facebook application using another technique.</p>
<p>Let&#8217;s read it:</p>
<p>&laquo; Hello, my name is <strong>Yarden Refaeli</strong> and I have been flash programmer for 1 year. A few weeks ago, I decided to make my first facebook flash game, <a href="http://apps.facebook.com/snaker-game" target= "_blank">Snaker</a>. Well, I won&#8217;t lie: It was HARD. After I made it to the end, I decided to write a tutorial about the best approach to build flash-facebook game. So let&#8217;s start! </p>
<p>First, we need to save our meta user-data about every user in OUR database, and for this we need to use a server-side language (in this tutorial I will talk about Mysql, but every other database or server-side language is fine). </p>
<p>Let&#8217;s say we want to make a game that save our score at the end, and then show us the score we got, and the scores of our friends. We need to save the score for every user, with it&#8217;s unique id, which can easily access through facebook APIs. Now lets say we want to do all the server-side jobs, with PHP and not flash: we don&#8217;t want to get the user-data we need from facebook-flash API, then send it all the way to the server and store it in the database, we want ALL the facebook/database related work, done on the server-side, with PHP. You should know, that you can access simple facebook library PHP code from flash, you need to authenticate first with the facebook function &#8220;set_user&#8221; with your user&#8217;s uid, and session key, that passed via the FBML tag in the flash vars. (for some strange reason, there is NO official documentation for this function AT ALL) <span id="more-1966"></span></p>
<p>Now, flash needs to communicate with the server-side (POST requests for example). We can build our own dandy classes in PHP and AS3 (as I did in the beginning), but why? We shouldn&#8217;t spend precious time on this task when we have AMFPHP! </p>
<p><a href="http://www.amfphp.org/" target="_blank"><strong>AMFPHP</strong></a> is a great open-source tool that allow flash to communicate with the server-side in a few lines of code! All you need to do, is of course, write the server-side functions, and then you can call it from your SWF, with Actionscript 3. </p>
<p>For example, if we want to get the user&#8217;s name from the server (using PHP and Facebook PHP-Platform), we need to create the following PHP class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> HiWorld <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> HiWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;path/to/facebook/PHP/platform&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHi<span style="color: #009900;">&#40;</span><span style="color: #000088;">$uid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sessionKey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$appapikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;fefcc99d6c09e56d9330d3d8e9e1d30a&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$appsecret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;eb5680d5137ba850487984ac75d97583&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$appapikey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$appsecret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_user</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sessionKey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users_getInfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Hi,&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, how do you do?&quot;</span><span style="color: #339933;">;</span>					
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>And save it in the &#8220;services&#8221; directory of AMFPHP, on our server. Now all we need to do is to call this function from our Actionscript 3 code, like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// required for flash file and output display</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #009900; font-style: italic;">// required to send/recieve data over AMF</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NetConnection</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Responder</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> gateway<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;path/to/gateway.php&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> connection<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">NetConnection</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> responder<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Responder</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> response_text<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// Responder to handle data returned from AMFPHP.</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>responder = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Responder</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>onResult<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>connection = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">NetConnection</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// Gateway.php url for NetConnection</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>connection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>gateway<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>respond_text = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>response_txt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// Get the auth vars from the flash vars</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> sessionKey<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">LoaderInfo</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_root<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parameters</span><span style="color: #000066; font-weight: bold;">.</span>fb_sig_session_key<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> uid<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">LoaderInfo</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_root<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parameters</span><span style="color: #000066; font-weight: bold;">.</span>fb_sig_user<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// call remote function</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>connection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;HiWorld.sayHi&quot;</span><span style="color: #000066; font-weight: bold;">,</span> responder<span style="color: #000066; font-weight: bold;">,</span> uid<span style="color: #000066; font-weight: bold;">,</span> sessionKey<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// Handle an AMF call. This method is defined by the responder. </span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onResult<span style="color: #000000;">&#40;</span>result<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>response_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>result<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>In this tutorial, we use the NetConnection class to connect flash and PHP. Actually, the NetConnect is more like the &#8220;pipe&#8221; between them, as all the data passed with it. The first parameter for the &#8220;connect&#8221; method of our connection object, is the className.function to call, the second is the responder object, and the others are the parameters for the function. When you call the remote function, you can pass as many parameters to PHP as the function require. The responder is an object with a reference to a function, (simple and stupid ;) ) that will be invoked when the request completed. When we get the data from the server, the &#8220;onResult&#8221; function called, with the result parameter. The result paramter is an object that the server returned. Our function simply cast it to string and put it in our text field. </p>
<p>Note: AMFPHP is also ENCRYPT the data sent (vice-versa), and automatically decrypt it as well in the other side.</p>
<p>This way, we can access all the data that facebook supply&#8230; Now only the skies are the real limit&#8230; This is what I&#8217;ve done in snaker (Actually, I&#8217;ve built a Highscore class in AS, that handle all the highscore and facebook related data). </p>
<p>This was my first tutorial ever about AMFPHP and facebook! Feel free to send me feedback to yard2010[at]gmail[dot]com! I hope you learned something new =] </p>
<p>All the code above most be in it&#8217;s appropriate place: PHP on compatible server, and the SWF must run only in a facebook canvas page with the fb:swf FBML tag! &raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/11/17/creation-of-a-flash-facebook-application-using-amfphp/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Creating a Flash Facebook application with the Facebook Actionscript API &#8211; part 2</title>
		<link>http://www.emanueleferonato.com/2009/11/11/creating-a-flash-facebook-application-with-the-facebook-actionscript-api-part-2/</link>
		<comments>http://www.emanueleferonato.com/2009/11/11/creating-a-flash-facebook-application-with-the-facebook-actionscript-api-part-2/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 17:16:09 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1949</guid>
		<description><![CDATA[It&#8217;s time to make some considerations on the Facebook application made with the Facebook Actionscript API I blogged some days ago. There was a doubt about putting a secret key in the swf file. Well, you should never give away your secret key, but let me point on two things: 1) You can encrypt your [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time to make some considerations on the <a href="http://www.emanueleferonato.com/2009/11/04/creating-a-flash-facebook-application-with-the-facebook-actionscript-api/">Facebook application made with the Facebook Actionscript API</a> I blogged some days ago.</p>
<p>There was a doubt about putting a secret key in the <code>swf</code> file.</p>
<p>Well, <strong>you should never give away your secret key</strong>, but let me point on two things:</p>
<p>1) You can encrypt your <code>swf</code> file, obfuscating the secret key&#8230; and just in case you think nothing is encrypted enough&#8230; surprise&#8230;</p>
<p>2) <strong>My Facebook application works without api and secret keys</strong>. That&#8217;s it&#8230; I tested it with more than one account, and everybody was able to use the application even if my keys are stored this way:</p>
<p><code>var api_key:String="xxxxxxxxxxxxxxxxxxxxxxx";<br />
var secret_key:String="yyyyyyyyyyyyyyyyyyyyyyy";</code></p>
<p>I am not hiding them, they are really a series of <code>x</code> and <code>y</code>&#8230; probably when you render a <code>swf</code> in <code>canvas</code> mode, they aren&#8217;t mandatory.</p>
<p>I have to say, I did not find docs about it, so take it as it comes.</p>
<p>The feature introduce this time is showing all your friends&#8230; there was a reader that was unable to populate a list with friend names, so here it is.</p>
<p>I didn&#8217;t create any list, but I&#8217;m simply showing them in a text area.<span id="more-1949"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Button<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// facebook libraries</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>Facebook<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>FacebookSessionUtil<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>commands<span style="color: #000066; font-weight: bold;">.</span>notifications<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>commands<span style="color: #000066; font-weight: bold;">.</span>friends<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>commands<span style="color: #000066; font-weight: bold;">.</span>stream<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>commands<span style="color: #000066; font-weight: bold;">.</span>users<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>users<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>friends<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>net<span style="color: #000066; font-weight: bold;">.</span>FacebookCall<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> facebook_demo <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> vars_field<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span>  <span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> friends_field<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span>  <span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> my_button<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fbook<span style="color: #000066; font-weight: bold;">:</span>Facebook<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// these are the api and secret keys you should be used to</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> api_key<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;xxxxxxxxxxxxxxxxxxxxxxx&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> secret_key<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;yyyyyyyyyyyyyyyyyyyyyyy&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// starting a new facebook session</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fb_session<span style="color: #000066; font-weight: bold;">:</span>FacebookSessionUtil=<span style="color: #0033ff; font-weight: bold;">new</span> FacebookSessionUtil<span style="color: #000000;">&#40;</span>api_key<span style="color: #000066; font-weight: bold;">,</span>secret_key<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// in this object I will store all variables Facebook will pass to the movie</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> passed_vars<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// this variable will hold all facebook API calls</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fbcall<span style="color: #000066; font-weight: bold;">:</span>FacebookCall<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> facebook_demo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// just placing some buttons...</span>
			place_buttons<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// just creating a text field...</span>
			create_vars_field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// initializing the session</span>
			fbook=fb_session<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// this function will just print out all variables Facebook is passing to the movie</span>
			get_vars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// getting friends uids (unique ids)</span>
			fbcall = <span style="color: #0033ff; font-weight: bold;">new</span> GetFriends<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			fbook<span style="color: #000066; font-weight: bold;">.</span>post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// function on_get_friends will be called once the post is completed</span>
			fbcall<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FacebookEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> on_get_friends<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// function to be called after GetFriends has finished</span>
		<span style="color: #339966; font-weight: bold;">function</span> on_get_friends<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>FacebookEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> friends = <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> <span style="color: #0033ff; font-weight: bold;">as</span> GetFriendsData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>friends<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> friends_num<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=friends<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> uids<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// loading all friends uids into an array</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>friends_num<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> user=friends<span style="color: #000066; font-weight: bold;">.</span>getItemAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> FacebookUser<span style="color: #000066; font-weight: bold;">;</span>
				uids<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>user<span style="color: #000066; font-weight: bold;">.</span>uid<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// retrieving informations for all uids contained in the uids array</span>
			fbcall=<span style="color: #0033ff; font-weight: bold;">new</span> GetInfo<span style="color: #000000;">&#40;</span>uids<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span>GetInfoFieldValues<span style="color: #000066; font-weight: bold;">.</span>ALL_VALUES<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			fbook<span style="color: #000066; font-weight: bold;">.</span>post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// the function on_friend_list_loaded will be called once the post is completed</span>
			fbcall<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FacebookEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> on_friend_list_loaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// function to be called after GetInfo has finished</span>
		<span style="color: #339966; font-weight: bold;">function</span> on_friend_list_loaded<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>FacebookEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> friends_data = <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> <span style="color: #0033ff; font-weight: bold;">as</span> GetInfoData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>userCollection<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> friends_num=friends_data<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// scanning all friends array and printing name and last name of each one</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>friends_num<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> user=friends_data<span style="color: #000066; font-weight: bold;">.</span>getItemAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				friends_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>user<span style="color: #000066; font-weight: bold;">.</span>first_name<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot; &quot;</span><span style="color: #000066; font-weight: bold;">+</span>user<span style="color: #000066; font-weight: bold;">.</span>last_name<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// this is the core function, the one that will handle clicks on buttons and publising notes or stories according</span>
		<span style="color: #009900; font-style: italic;">// to the button I am pressing</span>
		<span style="color: #339966; font-weight: bold;">function</span> onclick<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// retrieving the user id (it's one of the variables passed by Facebook)</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> uid<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>passed_vars<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;fb_sig_user&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Publish a note&quot;</span> <span style="color: #000066; font-weight: bold;">:</span>
					<span style="color: #009900; font-style: italic;">// publishing a note</span>
					fbcall=<span style="color: #0033ff; font-weight: bold;">new</span> SendNotification<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>uid<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;just sent a self-notification using &lt;a href = <span style="">\&quot;</span>http://apps.facebook.com/flash_demo/<span style="">\&quot;</span>&gt;Facebook Flash Demo&lt;/a&gt;&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;user_to_user&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					fbook<span style="color: #000066; font-weight: bold;">.</span>post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Publish a story&quot;</span> <span style="color: #000066; font-weight: bold;">:</span>
					<span style="color: #009900; font-style: italic;">// publishing a story</span>
					fbcall=<span style="color: #0033ff; font-weight: bold;">new</span> PublishPost<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;is using Facebook Flash Demo&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'name'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'Facebook Flash Demo'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'description'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'that<span style="">\'</span>s it'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'caption'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'this image was published by a Flash Movie'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'media'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'type'</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #990000;">'image'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'src'</span><span style="color: #000066; font-weight: bold;">:</span>  <span style="color: #990000;">'http://www.gamemummy.com/facebook/flash_demo/api.jpg'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">'href'</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'text'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'Visit Facebook Flash Demo'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span>uid<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					fbook<span style="color: #000066; font-weight: bold;">.</span>post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #339966; font-weight: bold;">function</span> create_vars_field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>vars_field<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			vars_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">340</span><span style="color: #000066; font-weight: bold;">;</span>
			vars_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">;</span>
			vars_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
			vars_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
			vars_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;DEFAULT VARS PASSED BY FACEBOOK:<span style="">\n</span><span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>friends_field<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			friends_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">340</span><span style="color: #000066; font-weight: bold;">;</span>
			friends_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">;</span>
			friends_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">350</span><span style="color: #000066; font-weight: bold;">;</span>
			friends_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
			friends_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;YOUR FACEBOOK FRIENDS (scroll with mousewheel):<span style="">\n</span><span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #339966; font-weight: bold;">function</span> get_vars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> varname<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> varvalue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
			passed_vars=<span style="color: #004993;">root</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parameters</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>varname <span style="color: #0033ff; font-weight: bold;">in</span> passed_vars<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				varvalue=<span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>passed_vars<span style="color: #000000;">&#91;</span>varname<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				vars_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>varname<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;:<span style="">\t</span>&quot;</span><span style="color: #000066; font-weight: bold;">+</span>varvalue<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #339966; font-weight: bold;">function</span> place_buttons<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> bnames<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Publish a note&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;Publish a story&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				my_button=<span style="color: #0033ff; font-weight: bold;">new</span> Button  <span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>my_button<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				my_button<span style="color: #000066; font-weight: bold;">.</span>label=bnames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				my_button<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">225</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				my_button<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span>onclick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The result as usual is on the <a target = "_blank" href="http://apps.facebook.com/flash_demo/">application page</a> and there is no need to download anything since you can just try it by just cutting/pasting the code on the example you can find at <a href="http://www.emanueleferonato.com/2009/11/04/creating-a-flash-facebook-application-with-the-facebook-actionscript-api/">this link</a>.</p>
<p>Can you all make the application work without api and secret keys?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/11/11/creating-a-flash-facebook-application-with-the-facebook-actionscript-api-part-2/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Creating a Flash Facebook application with the Facebook Actionscript API</title>
		<link>http://www.emanueleferonato.com/2009/11/04/creating-a-flash-facebook-application-with-the-facebook-actionscript-api/</link>
		<comments>http://www.emanueleferonato.com/2009/11/04/creating-a-flash-facebook-application-with-the-facebook-actionscript-api/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 00:11:33 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1851</guid>
		<description><![CDATA[It&#8217;s time to see how can we build a Flash Facebook application. What we are going to do is a Flash movie to be embedded in a Facebook application, able to interact with the user by publishing notes and stories on the wall. The first thing we need is the official Facebook Actionscript API. This [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time to see how can we build a Flash Facebook application.</p>
<p>What we are going to do is a Flash movie to be embedded in a Facebook application, able to interact with the user by publishing notes and stories on the wall.</p>
<p>The first thing we need is the official <a target = "_blank" href="http://code.google.com/p/facebook-actionscript-api/">Facebook Actionscript API</a>. This library contains all we need to create a complete Facebook Flash application.</p>
<p>You can download the source code at <a href="http://facebook-actionscript-api.googlecode.com/files/Facebook_library_v3.3_source.zip">this link</a>, but before messing with AS3, let&#8217;s create the PHP part.</p>
<p>I suggest you to read the <a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">Developing a Facebook Application for absolute beginners</a> posts from <a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">1</a> to <a href="http://www.emanueleferonato.com/2009/10/09/developing-a-facebook-application-for-absolute-beginners-step-5/">5</a> if you don&#8217;t know how to create a basic Facebook application.</p>
<p>Then, take a look at the PHP code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;style&gt;
     <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;style.css&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/style&gt;
&nbsp;
&lt;script&gt;
     function grant() {
         document.setLocation(&quot;http://apps.facebook.com/flash_demo/&quot;);
     }
&lt;/script&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$appapikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;xxxxxxx&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$appsecret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;yyyyyy&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$appapikey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$appsecret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$user_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">require_login</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$has_permission</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users_hasAppPermission</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;publish_stream&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$has_permission</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div class = &quot;allow&quot;&gt;You won't be able to test the flash demo if you don't allow publish stream permission -
&nbsp;
&lt;fb:prompt-permission perms=&quot;publish_stream&quot; next_fbjs=&quot;grant()&quot;&gt;&lt;strong&gt;ALLOW PERMISSION&lt;/strong&gt;&lt;/fb:prompt-permission&gt;&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;fb:swf swfsrc=&quot;http://www.gamemummy.com/facebook/flash_demo/facebook_demo.swf&quot; allowscriptaccess=&quot;always&quot; bgcolor=&quot;#ffffff&quot; flashvars=&quot;&quot; width=&quot;500&quot; height=&quot;400&quot;/&gt;</pre></td></tr></table></div>

<p>Notice at <strong>lines 1-3</strong> the way you can import CSS style sheets. Don&#8217;t forget to use <code>htmlentities</code> on the imported file.</p>
<p>Then, at <strong>lines 5-9</strong> I created a simple javascript function called <code>grant</code> that just redirects the browser to the application page. That is, basically it refreshes the page, and it will be called once the user will grant (or won&#8217;t grant) the permission to publish contents on his wall by submitting the permission form as you can see at <strong>line 30</strong>.</p>
<p>This is possible thanks to <code>next_fbjs="grant()"</code>.</p>
<p>Another important thing in this script you should arleady know is the way I ask for publishing permission.</p>
<p>You can ask for permission inside the Flash movie itself but I found it easier to ask directly from Php. This way, you can even hide the Flash movie if the user does not grant permissions.</p>
<p>But the core of the script, the think you did not see in previous tutorials is the way I include the Flash movie at <strong>line 34</strong> with the <code>fb:swf</code> tag.</p>
<p>You can find the official documentation at <a target = "_blank" href="http://wiki.developers.facebook.com/index.php/Fb:swf">this page</a>, and the most interesting thing is Facebook is passing some interesting parameters to the movie.<span id="more-1851"></span></p>
<p>Let&#8217;s see the Actionscript now&#8230; I used the button component to create the buttons but this is not important&#8230; here it is the commented script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Button<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// facebook rlibraries</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>Facebook<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>FacebookSessionUtil<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>commands<span style="color: #000066; font-weight: bold;">.</span>notifications<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>commands<span style="color: #000066; font-weight: bold;">.</span>stream<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">.</span>net<span style="color: #000066; font-weight: bold;">.</span>FacebookCall<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> facebook_demo <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> text_field<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> my_button<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fbook<span style="color: #000066; font-weight: bold;">:</span>Facebook<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// these are the api and secret keys you should be used to</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> api_key<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;xxxxxxxxxxxxxxx&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> secret_key<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;yyyyyyyyyyyyyyyy&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// starting a new facebook session</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fb_session<span style="color: #000066; font-weight: bold;">:</span>FacebookSessionUtil=<span style="color: #0033ff; font-weight: bold;">new</span> FacebookSessionUtil<span style="color: #000000;">&#40;</span>api_key<span style="color: #000066; font-weight: bold;">,</span>secret_key<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// in this object I will store all variables Facebook will pass to the movie</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> passed_vars<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// this variable will hold all facebook API calls</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fbcall<span style="color: #000066; font-weight: bold;">:</span>FacebookCall<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> facebook_demo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// just placing some buttons...</span>
			place_buttons<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// just creating a text field...</span>
			create_text_field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// initializing the session</span>
			fbook=fb_session<span style="color: #000066; font-weight: bold;">.</span>facebook<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// this function will just print out all variables Facebook is passing to the movie</span>
			get_vars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// this is the core function, the one that will handle clicks on buttons and publising notes or stories according</span>
		<span style="color: #009900; font-style: italic;">// to the button I am pressing</span>
		<span style="color: #339966; font-weight: bold;">function</span> onclick<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// retrieving the user id (it's one of the variables passed by Facebook)</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> uid<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>passed_vars<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;fb_sig_user&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Publish a note&quot;</span> <span style="color: #000066; font-weight: bold;">:</span>
					<span style="color: #009900; font-style: italic;">// publishing a note</span>
					fbcall=<span style="color: #0033ff; font-weight: bold;">new</span> SendNotification<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>uid<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;just sent a self-notification using &lt;a href = <span style="">\&quot;</span>http://apps.facebook.com/flash_demo/<span style="">\&quot;</span>&gt;Facebook Flash Demo&lt;/a&gt;&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;user_to_user&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					fbook<span style="color: #000066; font-weight: bold;">.</span>post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Publish a story&quot;</span> <span style="color: #000066; font-weight: bold;">:</span>
					<span style="color: #009900; font-style: italic;">// publishing a story</span>
					fbcall=<span style="color: #0033ff; font-weight: bold;">new</span> PublishPost<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;is using Facebook Flash Demo&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'name'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'Facebook Flash Demo'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'description'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'that<span style="">\'</span>s it'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'caption'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'this image was published by a Flash Movie'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'media'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'type'</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #990000;">'image'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'src'</span><span style="color: #000066; font-weight: bold;">:</span>  <span style="color: #990000;">'http://www.gamemummy.com/facebook/flash_demo/api.jpg'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">'href'</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">'text'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">'Visit Facebook Flash Demo'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span>uid<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					fbook<span style="color: #000066; font-weight: bold;">.</span>post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #339966; font-weight: bold;">function</span> create_text_field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>text_field<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			text_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">;</span>
			text_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">;</span>
			text_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
			text_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #339966; font-weight: bold;">function</span> get_vars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> varname<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> varvalue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
			passed_vars=<span style="color: #004993;">root</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parameters</span><span style="color: #000066; font-weight: bold;">;</span>
			text_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;DEFAULT VARS PASSED BY FACEBOOK:<span style="">\n</span><span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>varname <span style="color: #0033ff; font-weight: bold;">in</span> passed_vars<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				varvalue=<span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>passed_vars<span style="color: #000000;">&#91;</span>varname<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				text_field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>varname <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;:<span style="">\t</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> varvalue <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #339966; font-weight: bold;">function</span> place_buttons<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> bnames<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Publish a note&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;Publish a story&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				my_button=<span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>my_button<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				my_button<span style="color: #000066; font-weight: bold;">.</span>label=bnames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				my_button<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				my_button<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> onclick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The interesting thing of this script is the way you can send notifications (<strong>line 44</strong>) and publish posts (<strong>line 49</strong>)&#8230; I won&#8217;t talk about notifications because <a href="http://wiki.developers.facebook.com/index.php/Notifications.send" target = "_blank">Facebook will deprecate this method in late November/early December 2009</a> , but I want you to look at the way I publish the post following the format explained at the <a href="http://wiki.developers.facebook.com/index.php/Attachment_%28Streams%29" target = "_blank">official attachment docs</a>.</p>
<p>You can <a href="http://apps.facebook.com/flash_demo/" target = "_blank">test the application at this page</a> and <a href="/downloads/facebook_demo.zip">download the full source code</a>, library included.</p>
<p>Next time, we&#8217;ll see how to add more functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/11/04/creating-a-flash-facebook-application-with-the-facebook-actionscript-api/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Horror Profile: Facebook application</title>
		<link>http://www.emanueleferonato.com/2009/10/28/horror-profile-facebook-application/</link>
		<comments>http://www.emanueleferonato.com/2009/10/28/horror-profile-facebook-application/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 11:37:16 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1811</guid>
		<description><![CDATA[You are all invited to try Horror Profile, a Facebook application I made in about an hour. The application takes your name and profile photo, and combines them in a creepy environment to create an horrific photo that you can upload to your album. During next days I&#8217;ll release the full tutorial to create an [...]]]></description>
			<content:encoded><![CDATA[<p>You are all invited to try <a target = "_blank" href="http://apps.facebook.com/horror_name/"><strong>Horror Profile</strong></a>, a Facebook application I made in about an hour.</p>
<p><a target = "_blank" href="http://apps.facebook.com/horror_name/"><img src="http://www.emanueleferonato.com/wp-content/uploads/2009/10/horror_profile.jpg" alt="horror_profile" title="horror_profile" /></a></p>
<p>The application takes your name and profile photo, and combines them in a creepy environment to create an horrific photo that you can upload to your album.</p>
<p>During next days I&#8217;ll release the full tutorial to create an application with ads, photo uploads, dynamic text generation, and all the features you see in the application.</p>
<p>Meanwhile, <a target = "_blank" href="http://apps.facebook.com/horror_name/"><strong>Play with it</strong></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/10/28/horror-profile-facebook-application/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 10/18 queries in 0.039 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-10 20:31:41 -->
