<?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; Php</title>
	<atom:link href="http://www.emanueleferonato.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Mon, 15 Mar 2010 20:23:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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, 4 [...]]]></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;
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
     <span style="color: #000000; font-weight: bold;">function</span> grant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         document<span style="color: #339933;">.</span>setLocation<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://apps.facebook.com/horror_name/?pub=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
&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;
<span style="color: #339933;">&lt;</span>style<span style="color: #339933;">&gt;</span>
     <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>
<span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>Hello <span style="color: #339933;">&lt;</span>fb<span style="color: #339933;">:</span>name uid<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$user_id</span>; ?&gt;&quot;</span> useyou<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;false&quot;</span> linked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;false&quot;</span> firstnameonly<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">&gt;&lt;/</span>fb<span style="color: #339933;">:</span>name<span style="color: #339933;">&gt;,</span> let<span style="color: #0000ff;">'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/&lt;?php echo $user_id; ?&gt;.jpg&quot; /&gt;&lt;/div&gt;
&nbsp;
&lt;?php if(!$has_permission){ ?&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>8</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 1 year. A [...]]]></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;">// 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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> fl.events.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #009900;">// 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: #004993;">NetConnection</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">Responder</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <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: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;path/to/gateway.php&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> connection<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">NetConnection</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> responder<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Responder</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> response_text<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">TextField</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;">// Responder to handle data returned from AMFPHP.</span>
			<span style="color: #0033ff; font-weight: bold;">this</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>.onResult<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.connection = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">NetConnection</span>;
			<span style="color: #009900;">// Gateway.php url for NetConnection</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.connection.<span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.gateway<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</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: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.response_txt<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Get the auth vars from the flash vars</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> sessionKey<span style="color: #000000; 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>._root.<span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">parameters</span>.fb_sig_session_key;
			<span style="color: #6699cc; font-weight: bold;">var</span> uid<span style="color: #000000; 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>._root.<span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">parameters</span>.fb_sig_user;
&nbsp;
			<span style="color: #009900;">// call remote function</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.connection.<span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;HiWorld.sayHi&quot;</span>, responder, uid, sessionKey<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; 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>.response_txt.<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: #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>8</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 swf file, obfuscating [...]]]></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: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> fl.controls.Button;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
	<span style="color: #009900;">// facebook libraries</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.Facebook;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.utils.FacebookSessionUtil;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.notifications.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.friends.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.stream.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.users.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.events.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.<span style="color: #004993;">data</span>.users.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.<span style="color: #004993;">data</span>.friends.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.net.FacebookCall;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> facebook_demo extends <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: #000000; 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: #6699cc; font-weight: bold;">var</span> friends_field<span style="color: #000000; 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: #6699cc; font-weight: bold;">var</span> my_button<span style="color: #000000; font-weight: bold;">:</span>Button;
		<span style="color: #6699cc; font-weight: bold;">var</span> fbook<span style="color: #000000; font-weight: bold;">:</span>Facebook;
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;xxxxxxxxxxxxxxxxxxxxxxx&quot;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> secret_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;yyyyyyyyyyyyyyyyyyyyyyy&quot;</span>;
		<span style="color: #009900;">// starting a new facebook session</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fb_session<span style="color: #000000; font-weight: bold;">:</span>FacebookSessionUtil=<span style="color: #0033ff; font-weight: bold;">new</span> FacebookSessionUtil<span style="color: #000000;">&#40;</span>api_key,secret_key,<span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #009900;">// this variable will hold all facebook API calls</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fbcall<span style="color: #000000; font-weight: bold;">:</span>FacebookCall;
		<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;">// just placing some buttons...</span>
			place_buttons<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// just creating a text field...</span>
			create_vars_field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// initializing the session</span>
			fbook=fb_session.facebook;
			<span style="color: #009900;">// 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: #009900;">// 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>;
			fbook.post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// function on_get_friends will be called once the post is completed</span>
			fbcall.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FacebookEvent.<span style="color: #004993;">COMPLETE</span>, on_get_friends<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span>FacebookEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; 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: #004993;">data</span> <span style="color: #0033ff; font-weight: bold;">as</span> GetFriendsData<span style="color: #000000;">&#41;</span>.friends;
			<span style="color: #6699cc; font-weight: bold;">var</span> friends_num<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=friends.<span style="color: #004993;">length</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> uids<span style="color: #000000; 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: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span>friends_num; i<span style="color: #000000; 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.getItemAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> FacebookUser;
				uids.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>user.uid<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900;">// 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: #000000;">&#91;</span>GetInfoFieldValues.ALL_VALUES<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
			fbook.post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// the function on_friend_list_loaded will be called once the post is completed</span>
			fbcall.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FacebookEvent.<span style="color: #004993;">COMPLETE</span>, on_friend_list_loaded<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900;">// 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: #000000; 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: #004993;">data</span> <span style="color: #0033ff; font-weight: bold;">as</span> GetInfoData<span style="color: #000000;">&#41;</span>.userCollection<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> friends_num=friends_data.<span style="color: #004993;">length</span>;
			<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span>friends_num; i<span style="color: #000000; 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.getItemAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
				friends_field.<span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>user.first_name<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot; &quot;</span><span style="color: #000000; font-weight: bold;">+</span>user.last_name<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900;">// this is the core function, the one that will handle clicks on buttons and publising notes or stories according</span>
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// 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: #000000; 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: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">currentTarget</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: #000000; font-weight: bold;">:</span>
					<span style="color: #009900;">// 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: #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: #990000;">&quot;user_to_user&quot;</span><span style="color: #000000;">&#41;</span>;
					fbook.post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Publish a story&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
					<span style="color: #009900;">// 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: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span>,<span style="color: #990000;">'name'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'Facebook Flash Demo'</span>,<span style="color: #990000;">'description'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'that<span style="">\'</span>s it'</span>,<span style="color: #990000;">'caption'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'this image was published by a Flash Movie'</span>,<span style="color: #990000;">'media'</span><span style="color: #000000; 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: #000000; font-weight: bold;">:</span> <span style="color: #990000;">'image'</span>,<span style="color: #990000;">'src'</span><span style="color: #000000; font-weight: bold;">:</span>  <span style="color: #990000;">'http://www.gamemummy.com/facebook/flash_demo/api.jpg'</span>, <span style="color: #990000;">'href'</span><span style="color: #000000; 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: #000000;">&#91;</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span>,<span style="color: #990000;">'text'</span><span style="color: #000000; 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>,uid.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
					fbook.post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">break</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: #000000; 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>;
			vars_field.<span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">340</span>;
			vars_field.<span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">320</span>;
			vars_field.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">0</span>;
			vars_field.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">10</span>;
			vars_field.<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: #004993;">addChild</span><span style="color: #000000;">&#40;</span>friends_field<span style="color: #000000;">&#41;</span>;
			friends_field.<span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">340</span>;
			friends_field.<span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">320</span>;
			friends_field.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">350</span>;
			friends_field.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">10</span>;
			friends_field.<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: #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: #000000; 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> varvalue<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
			passed_vars=<span style="color: #004993;">root</span>.<span style="color: #004993;">loaderInfo</span>.<span style="color: #004993;">parameters</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>;
				vars_field.<span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>varname<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;:<span style="">\t</span>&quot;</span><span style="color: #000000; font-weight: bold;">+</span>varvalue<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</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: #000000; 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: #000000; 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: #990000;">&quot;Publish a story&quot;</span><span style="color: #000000;">&#41;</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: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">2</span>; i<span style="color: #000000; 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: #004993;">addChild</span><span style="color: #000000;">&#40;</span>my_button<span style="color: #000000;">&#41;</span>;
				my_button.label=bnames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
				my_button.move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">225</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">*</span>i,<span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000;">&#41;</span>;
				my_button.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,onclick<span style="color: #000000;">&#41;</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>7</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 library contains [...]]]></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: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> fl.controls.Button;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
	<span style="color: #009900;">// facebook rlibraries</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.Facebook;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.utils.FacebookSessionUtil;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.notifications.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.stream.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.net.FacebookCall;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> facebook_demo extends <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: #000000; 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: #6699cc; font-weight: bold;">var</span> my_button<span style="color: #000000; font-weight: bold;">:</span>Button;
		<span style="color: #6699cc; font-weight: bold;">var</span> fbook<span style="color: #000000; font-weight: bold;">:</span>Facebook;
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;xxxxxxxxxxxxxxx&quot;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> secret_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;yyyyyyyyyyyyyyyy&quot;</span>;
		<span style="color: #009900;">// starting a new facebook session</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fb_session<span style="color: #000000; font-weight: bold;">:</span>FacebookSessionUtil=<span style="color: #0033ff; font-weight: bold;">new</span> FacebookSessionUtil<span style="color: #000000;">&#40;</span>api_key,secret_key,<span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #009900;">// this variable will hold all facebook API calls</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> fbcall<span style="color: #000000; font-weight: bold;">:</span>FacebookCall;
		<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;">// just placing some buttons...</span>
			place_buttons<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// just creating a text field...</span>
			create_text_field<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// initializing the session</span>
			fbook=fb_session.facebook;
			<span style="color: #009900;">// 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: #000000;">&#125;</span>
		<span style="color: #009900;">// this is the core function, the one that will handle clicks on buttons and publising notes or stories according</span>
		<span style="color: #009900;">// 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// 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: #000000; 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: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">currentTarget</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: #000000; font-weight: bold;">:</span>
					<span style="color: #009900;">// 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: #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: #990000;">&quot;user_to_user&quot;</span><span style="color: #000000;">&#41;</span>;
					fbook.post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Publish a story&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
					<span style="color: #009900;">// 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: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span>,<span style="color: #990000;">'name'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'Facebook Flash Demo'</span>,<span style="color: #990000;">'description'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'that<span style="">\'</span>s it'</span>,<span style="color: #990000;">'caption'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'this image was published by a Flash Movie'</span>,<span style="color: #990000;">'media'</span><span style="color: #000000; 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: #000000; font-weight: bold;">:</span> <span style="color: #990000;">'image'</span>,<span style="color: #990000;">'src'</span><span style="color: #000000; font-weight: bold;">:</span>  <span style="color: #990000;">'http://www.gamemummy.com/facebook/flash_demo/api.jpg'</span>, <span style="color: #990000;">'href'</span><span style="color: #000000; 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: #000000;">&#91;</span><span style="color: #000000;">&#123;</span><span style="color: #990000;">'href'</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">'http://apps.facebook.com/flash_demo/'</span>,<span style="color: #990000;">'text'</span><span style="color: #000000; 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>,uid.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
					fbook.post<span style="color: #000000;">&#40;</span>fbcall<span style="color: #000000;">&#41;</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: #000000; 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>;
			text_field.<span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">500</span>;
			text_field.<span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">320</span>;
			text_field.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">10</span>;
			text_field.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">10</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: #000000; 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: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> varvalue<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
			passed_vars=<span style="color: #004993;">root</span>.<span style="color: #004993;">loaderInfo</span>.<span style="color: #004993;">parameters</span>;
			text_field.<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: #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>;
				text_field.<span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>varname <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;:<span style="">\t</span>&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> varvalue <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</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: #000000; 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: #000000; 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: #990000;">&quot;Publish a story&quot;</span><span style="color: #000000;">&#41;</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: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">2</span>; i<span style="color: #000000; 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: #004993;">addChild</span><span style="color: #000000;">&#40;</span>my_button<span style="color: #000000;">&#41;</span>;
				my_button.label=bnames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
				my_button.move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">*</span>i, <span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000;">&#41;</span>;
				my_button.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, onclick<span style="color: #000000;">&#41;</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>21</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 application with [...]]]></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>4</slash:comments>
		</item>
		<item>
		<title>Developing a Facebook Application for absolute beginners &#8211; step 5</title>
		<link>http://www.emanueleferonato.com/2009/10/09/developing-a-facebook-application-for-absolute-beginners-step-5/</link>
		<comments>http://www.emanueleferonato.com/2009/10/09/developing-a-facebook-application-for-absolute-beginners-step-5/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 14:33:11 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1727</guid>
		<description><![CDATA[Welcome to the 5th step.
Let&#8217;s make a small recap:
Step 1: Creation of the application itself
Step 2: Publishing a text on the user&#8217;s status
Step 3: Publishing text, links and images on the user&#8217;s wall
Step 4: Inviting friends to use the application
Now it&#8217;s time to make the application post a notification to users you invite to join [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the 5th step.</p>
<p>Let&#8217;s make a small recap:</p>
<p><a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">Step 1</a>: Creation of the application itself</p>
<p><a href="http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/">Step 2</a>: Publishing a text on the user&#8217;s status</p>
<p><a href="http://www.emanueleferonato.com/2009/09/30/developing-a-facebook-application-for-absolute-beginners-%E2%80%93-step-3/">Step 3</a>: Publishing text, links and images on the user&#8217;s wall</p>
<p><a href="http://www.emanueleferonato.com/2009/10/07/developing-a-facebook-application-for-absolute-beginners-step-4/">Step 4</a>: Inviting friends to use the application</p>
<p>Now it&#8217;s time to make the application post a notification to users you invite to join the app.</p>
<p>I mean this one:</p>
<p><img src="/wp-content/uploads/2009/10/invite.jpg" alt="invite" /></p>
<p>The script now is this one:<span id="more-1727"></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
</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;">require_once</span> <span style="color: #0000ff;">'facebook.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$appapikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxx'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$appsecret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxx'</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;">$friends</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;">friends_get</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;p&gt;Hello &lt;fb:name uid=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$user_id</span><span style="color: #000099; font-weight: bold;">\&quot;</span> useyou=<span style="color: #000099; font-weight: bold;">\&quot;</span>false<span style="color: #000099; font-weight: bold;">\&quot;</span> linked=<span style="color: #000099; font-weight: bold;">\&quot;</span>false<span style="color: #000099; font-weight: bold;">\&quot;</span> firstnameonly=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/fb:name&gt;, you have &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$friends</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$friend</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$infos</span><span style="color: #339933;">.=</span><span style="color: #000088;">$friend</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$infos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$infos</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$infos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gender</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;">$infos</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'sex'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gender_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$gendervalue</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$gendervalue</span><span style="color: #009900;">&#91;</span>sex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$male</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>male<span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>male<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>female<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: #000088;">$female</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">-</span><span style="color: #000088;">$male</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&lt;li&gt;Males: <span style="color: #006699; font-weight: bold;">$male</span>%&lt;/li&gt;&lt;li&gt;Females: <span style="color: #006699; font-weight: bold;">$female</span>%&lt;/li&gt;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;has &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends. <span style="color: #006699; font-weight: bold;">$male</span><span style="color: #009933; font-weight: bold;">% o</span>f them are male. <span style="color: #006699; font-weight: bold;">$female</span>% are female&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span>type<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span>src<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.gamemummy.com/facebook/genderz_demo/genderz.png&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span>href<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://apps.facebook.com/genderz_demo/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;Try the application!!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>href<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://apps.facebook.com/genderz_demo/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>caption<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{*actor*} has &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>description<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;powered by genderz_demo&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>media<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</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>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;fb:prompt-permission perms=<span style="color: #000099; font-weight: bold;">\&quot;</span>publish_stream<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Publish results on your wall!!&lt;/fb:prompt-permission&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;">$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;">stream_publish</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #000088;">$attachment</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>ids<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;is inviting you to use &lt;a href = <span style="color: #000099; font-weight: bold;">\&quot;</span>http://apps.facebook.com/genderz_demo/<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;genderz_demo&lt;/a&gt;!! Try it!&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$ids_list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>ids<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">notifications_send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ids_list</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'user_to_user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;br /&gt;Thank you for inviting &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>ids<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends to genderz_demo&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>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;fb:request-form
     action=&quot;http://apps.facebook.com/genderz_demo/&quot;
     method=&quot;POST&quot; 
     type=&quot;genderz_demo&quot; 
     content=&quot;Hello. Please use my app. <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: #0000ff;">&quot;&lt;fb:req-choice url=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://apps.facebook.com/genderz_demo/<span style="color: #000099; font-weight: bold;">\&quot;</span> label=<span style="color: #000099; font-weight: bold;">\&quot;</span>Try it!!<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; &gt;
     &lt;fb:multi-friend-selector showborder=&quot;false&quot; actiontext=&quot;Send some spam invites to Genderz Demo!&quot;&gt; 
&lt;/fb:request-form&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></pre></td></tr></table></div>

<p><strong>Lines 68-74</strong> are the same we added at <a href="http://www.emanueleferonato.com/2009/10/07/developing-a-facebook-application-for-absolute-beginners-step-4/">Step 4</a>, but they are in an <code>else</code> condition because they will appear only if I don&#8217;t have a variable called <code>ids</code> passed with <code>POST</code> (<strong>line 58</strong>).</p>
<p>This means I show the invite friends selector only if I haven&#8217;t already invited some friends, because when I submit an invitation form, an <code>ids</code> variable is passed with an array containing all of the user IDs of the people I invited.</p>
<p>Now let&#8217;s see what happens at <strong>lines 59-62</strong>, executed only once I submitted the request form.</p>
<p><strong>Line 59</strong>: writing my note. Notice as my note stats with &#8220;is inviting&#8221; and not with &#8220;Emanuele Feronato is inviting&#8221;, because when I specify <code>user_to_user</code> in the note mode at <strong>line 61</strong>, the API will add my name by itself.</p>
<p><strong>Line 60</strong>: transforming an array into a comma separated value string of all of the user IDs of the people I invited.</p>
<p><strong>Line 61</strong>: <code>notifications_send</code> takes as input the list created at <strong>line 60</strong>, the message created at <strong>line 59</strong> and sends the note as user_to_user as explained before.</p>
<p>Finally, <strong>line 62</strong> thanks the user for sending some spam :)</p>
<p>And the application is finished&#8230; during next step I&#8217;ll show you how to finetune it in order to make it seem a professional application, then we&#8217;ll see the hardest part: monetization.</p>
<p><a target = "_blank" href="http://apps.facebook.com/genderz_demo/">Try the application</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/10/09/developing-a-facebook-application-for-absolute-beginners-step-5/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>WordPress plugin prototype to check the date and time that wp files have been last modified</title>
		<link>http://www.emanueleferonato.com/2009/10/08/wordpress-plugin-prototype-to-check-the-date-and-time-that-wp-files-have-been-last-modified/</link>
		<comments>http://www.emanueleferonato.com/2009/10/08/wordpress-plugin-prototype-to-check-the-date-and-time-that-wp-files-have-been-last-modified/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 20:20:41 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1723</guid>
		<description><![CDATA[Like some of you noticed during these days, my blog was hacked.
Someone injected an encoded javascript code into my footer.php theme making my site open an iframe with some badware.
The same old things that happen when you&#8217;re famous :)
The boring part of this story is now I check for my WP files every day, to [...]]]></description>
			<content:encoded><![CDATA[<p>Like some of you noticed during these days, my blog was hacked.</p>
<p>Someone injected an encoded javascript code into my <code>footer.php</code> theme making my site open an iframe with some badware.</p>
<p>The same old things that happen when you&#8217;re famous :)</p>
<p>The boring part of this story is now I check for my WP files every day, to prevent code injection, until I&#8217;ll find the way hackers use to inject such code.</p>
<p>So I developed a very basic plugin to do this job for me. It scans my themes directory and outputs the files modified in the last 24 hours.</p>
<p>I don&#8217;t know if I&#8217;ll turn this prototype into a real, finished, plugin&#8230; but meanwhile you can take a look at the 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
35
36
37
38
39
40
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Check file dates
Plugin URI: http://www.emanueleferonato.com/
Description: Checks the date and time that wp files have been last modified.
Author: Emanuele Feronato
Version: 1.0
Author URI: http://www.emanueleferonato.com/
*/</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_plugin_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> add_plugin_pages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    add_menu_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Check dates'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Check dates'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mt_toplevel_page'</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;">function</span> date_tree<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_dir</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$dirs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_diff</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;..&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               date_tree<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</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;">$mod_date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</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;">$mod_date</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$date</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;li&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$start_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&lt;strong&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/strong&gt; -&gt; &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> mt_toplevel_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-1 day&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; 00:00:00&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;Searching for files modified after &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$date</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
     date_tree<span style="color: #009900;">&#40;</span>get_theme_root<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&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>And outputs something like this:</p>
<p><code><strong>Searching for files modified after 2009-10-07 00:00:00</strong><br />
<strong>footer.php</strong> -> 2009-10-07 23:31:56<br />
<strong>header.php</strong> -> 2009-10-08 17:58:14</code></p>
<p>If you want to try it, simply create a new file into your plugins directory and paste this code.</p>
<p>If you see some interesting use out of it by adding some options, let me know and maybe I&#8217;ll finish it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/10/08/wordpress-plugin-prototype-to-check-the-date-and-time-that-wp-files-have-been-last-modified/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Developing a Facebook Application for absolute beginners &#8211; Step 4</title>
		<link>http://www.emanueleferonato.com/2009/10/07/developing-a-facebook-application-for-absolute-beginners-step-4/</link>
		<comments>http://www.emanueleferonato.com/2009/10/07/developing-a-facebook-application-for-absolute-beginners-step-4/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 08:54:23 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1716</guid>
		<description><![CDATA[The best way to do some viral marketing through Facebook is using inite forms to allow users to share applications with their friends who might not have otherwise known about them.
Since users are invited to use applications by friends, they are (at the moment) likely to view each invite request, providing them an opportunity to [...]]]></description>
			<content:encoded><![CDATA[<p>The best way to do some viral marketing through Facebook is using inite forms to allow users to share applications with their friends who might not have otherwise known about them.</p>
<p>Since users are invited to use applications by friends, they are (at the moment) likely to view each invite request, providing them an opportunity to be converted into an application user as well.</p>
<p>I wrote &#8220;at the moment&#8221; because there is a thin line between friends invites and spam. I have friends inviting me every given day to join pointless groups or something similar.</p>
<p>Moreover, it&#8217;s possible (but really lame) to make the invitation mandatory in order to continue with the application (I found a test giving you the result only after I sent the invitation to 20 friends).</p>
<p>Although possible, this is really a malpractice, and the <a target = "_blank" href="http://www.facebook.com/group.php?gid=22656145393">Stop forcing me to &#8220;Invite 20 Friends&#8221;!!</a> group is just one of many complaints.</p>
<p>Anyway, assuming you are using the invitation form in a polite way, this is what you should add to the script seen in <a href="http://www.emanueleferonato.com/2009/09/30/developing-a-facebook-application-for-absolute-beginners-%E2%80%93-step-3/">step 3</a> after the Php close tag <code>?></code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;fb:request-form
     action=&quot;http://apps.facebook.com/genderz_demo/&quot;
     method=&quot;POST&quot; 
     type=&quot;genderz_demo&quot; 
     content=&quot;Hello. Please use my app. &lt;?php echo htmlentities(&quot;&lt;fb:req-choice url=\&quot;http://apps.facebook.com/genderz_demo/\&quot; label=\&quot;Try it!!\&quot;&quot;) ?&gt;&quot; &gt;
     &lt;fb:multi-friend-selector showborder=&quot;false&quot; actiontext=&quot;Send some spam invites to Genderz Demo!&quot;&gt; 
&lt;/fb:request-form&gt;</pre></td></tr></table></div>

<p><span id="more-1716"></span></p>
<p><strong>Line 60</strong>: <code>request-form</code> tag creates a form that sends requests to the selected users.</p>
<p><strong>Line 61</strong>: the <code>action</code> of the form, just like an HTML form &#8211; it&#8217;s the URL where a user gets redirected after submitting or skipping the form</p>
<p><strong>Line 62</strong>: the <code>method</code>, can be <code>GET</code> or <code>POST</code> just like HTML forms. If you aren&#8217;t familiar with HTML forms, always use <code>POST</code></p>
<p><strong>Line 63</strong>: the <code>type</code>, typically your application name</p>
<p><strong>Line 64</strong>: the <code>content</code>, that&#8217;s the contents of the request or invitation to be sent. It should use FBML formatting that contains only links and the special tag <code><fb:req-choice url="" label="" /></code> to specify the buttons to be included in the request. It must be encoded with <code>htmlentities</code> PHP function.</p>
<p>In the <code>req-choice</code> tag you will specify the url of your application and the text shown in the label inviting the friend to launch the application.</p>
<p>Your friend will display the invitation this way:</p>
<p><img src="/wp-content/uploads/2009/10/invite01.png" /></p>
<p>notice the <code>Hello. Please use my app.</code> and the <code>Try it!!</code> strings</p>
<p><strong>Line 65</strong>: <code>multi-friend-selector</code> tag opens the big friends selector</p>
<p><img src="/wp-content/uploads/2009/10/invite02.png" /></p>
<p>Here, notice the <code>Send some spam invites to Genderz Demo!</code> string.</p>
<p>A user may invite a number of people each day equal to the maximum number of requests allocated to your application (only 4, in my application). If a user attempts to go over this limit, he will get an error</p>
<p><strong>Line 66</strong>: Always close opened tags&#8230;</p>
<p>And now you have a wonderful invite form! Next step, notifications!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/10/07/developing-a-facebook-application-for-absolute-beginners-step-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Developing a Facebook Application for absolute beginners – step 3</title>
		<link>http://www.emanueleferonato.com/2009/09/30/developing-a-facebook-application-for-absolute-beginners-%e2%80%93-step-3/</link>
		<comments>http://www.emanueleferonato.com/2009/09/30/developing-a-facebook-application-for-absolute-beginners-%e2%80%93-step-3/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 20:04:40 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1696</guid>
		<description><![CDATA[In step 1 we created a simple Facebook application, and in step 2 we made our application able to write on the wall
Now it&#8217;s time to add images and more text to users&#8217; wall when they run the application.
This is what I am creating:

I know I wrote &#8220;appliction&#8221;&#8230; but it was a typo&#8230; don&#8217;t make [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">step 1</a> we created a simple Facebook application, and in <a href="http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/">step 2</a> we made our application able to write on the wall</p>
<p>Now it&#8217;s time to add images and more text to users&#8217; wall when they run the application.</p>
<p>This is what I am creating:</p>
<p><img src="/images/gendz03.png" alt="" /></p>
<p>I know I wrote &#8220;appliction&#8221;&#8230; but it was a typo&#8230; don&#8217;t make me take another screenshot (lazy geek&#8230;)</p>
<p>In order to do this, you will need to know how to include attachments.</p>
<p>You can add a lot of rich information to a post by including an attachment. The attachment gives you the opportunity to expand on the post by describing what the user did in your application. </p>
<p>This is the script:<span id="more-1696"></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
</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;">require_once</span> <span style="color: #0000ff;">'facebook.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$appapikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxxxxxxxxxx'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$appsecret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxxxxxxxxxx'</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;">$friends</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;">friends_get</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;p&gt;Hello &lt;fb:name uid=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$user_id</span><span style="color: #000099; font-weight: bold;">\&quot;</span> useyou=<span style="color: #000099; font-weight: bold;">\&quot;</span>false<span style="color: #000099; font-weight: bold;">\&quot;</span> linked=<span style="color: #000099; font-weight: bold;">\&quot;</span>false<span style="color: #000099; font-weight: bold;">\&quot;</span> firstnameonly=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/fb:name&gt;, you have &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$friends</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$friend</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$infos</span><span style="color: #339933;">.=</span><span style="color: #000088;">$friend</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$infos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$infos</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$infos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gender</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;">$infos</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'sex'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gender_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$gendervalue</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$gendervalue</span><span style="color: #009900;">&#91;</span>sex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$male</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>male<span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>male<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>female<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: #000088;">$female</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">-</span><span style="color: #000088;">$male</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&lt;li&gt;Males: <span style="color: #006699; font-weight: bold;">$male</span>%&lt;/li&gt;&lt;li&gt;Females: <span style="color: #006699; font-weight: bold;">$female</span>%&lt;/li&gt;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;has &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends. <span style="color: #006699; font-weight: bold;">$male</span><span style="color: #009933; font-weight: bold;">% o</span>f them are male. <span style="color: #006699; font-weight: bold;">$female</span>% are female&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span>type<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span>src<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.gamemummy.com/facebook/genderz_demo/genderz.png&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span>href<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://apps.facebook.com/genderz_demo/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;Try the appliction!!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>href<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://apps.facebook.com/genderz_demo/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>caption<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{*actor*} has &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>description<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;powered by genderz_demo&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span>media<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</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>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;fb:prompt-permission perms=<span style="color: #000099; font-weight: bold;">\&quot;</span>publish_stream<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Publish results on your wall!!&lt;/fb:prompt-permission&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;">$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;">stream_publish</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #000088;">$attachment</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></pre></td></tr></table></div>

<p><strong>Line 37</strong>: declaring an array called <code>$image</code>&#8230; it will store all image information such as type (<strong>line 38</strong>), source (<strong>line 39</strong>) and link (<strong>line 40</strong>)</p>
<p><strong>Line 42</strong>: declaring an array called <code>$attachment</code> that will store all attachment information.</p>
<p>You can save a lot of information in the array by using these fields, that&#8217;s what I used:</p>
<p><strong>name</strong>: The title of the post (<strong>line 43</strong>). The post should fit on one line in a user&#8217;s stream; make sure you account for the width of any thumbnail.</p>
<p><strong>href</strong>: The URL to the source of the post referenced in the name (<strong>line 44</strong>) . The URL should not be longer than 1024 characters.</p>
<p><strong>caption</strong>: A subtitle for the post that should describe why the user posted the item or the action the user took (<strong>line 45</strong>) . This field can contain plain text only, as well as the <code>{*actor*}</code> token, which gets replaced by a link to the profile of the session user. The caption should fit on one line in a user&#8217;s stream; make sure you account for the width of any thumbnail.</p>
<p><strong>description</strong>: Descriptive text about the story (<strong>line 46</strong>). This field can contain plain text only and should be no longer than is necessary for a reader to understand the story.</p>
<p><strong>media</strong>: Rich media that provides visual content for the post (<strong>line 47</strong>) . <code>media</code> is an array that contains one of the following types: image, flash, mp3, or video, Make sure you specify only one of these types in your post. I attached the <code>$image</code> array, so my media is an image.</p>
<p>Finally at <strong>line 55</strong> I send both the text created at <a href="http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/">step 2</a> and the attachment to the wall.</p>
<p><a href="http://apps.facebook.com/genderz_demo/" target = "_blank">Take a look at the application</a>  and see how does it publish your friends gender stats on your profile.</p>
<p>Next time, some more improvements and a chart, as suggested by a reader.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/09/30/developing-a-facebook-application-for-absolute-beginners-%e2%80%93-step-3/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Developing a Facebook Application for absolute beginners &#8211; step 2</title>
		<link>http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/</link>
		<comments>http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 15:21:37 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1686</guid>
		<description><![CDATA[It&#8217;s time to add some features to the application we created in step 1.
This time we&#8217;ll add some interaction with Facebook, such as publishing results on your wall.
The new script is this one:

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
&#60;?php
&#160;
require_once 'facebook.php';
&#160;
$appapikey = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$appsecret = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
&#160;
$facebook = new Facebook&#40;$appapikey, $appsecret&#41;;
&#160;
$user_id = $facebook-&#62;require_login&#40;&#41;;
&#160;
$friends = $facebook-&#62;api_client-&#62;friends_get&#40;&#41;;
&#160;
echo &#34;&#60;p&#62;Hello &#60;fb:name uid=\&#34;$user_id\&#34; useyou=\&#34;false\&#34; linked=\&#34;false\&#34; firstnameonly=\&#34;true\&#34;&#62;&#60;/fb:name&#62;, you have &#34;.count&#40;$friends&#41;.&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time to add some features to the application we created in <a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">step 1</a>.</p>
<p>This time we&#8217;ll add some interaction with Facebook, such as publishing results on your wall.</p>
<p>The new script is this one:</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
</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;">require_once</span> <span style="color: #0000ff;">'facebook.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$appapikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxxxxxxxxxxxxxxxxxxxxxx'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$appsecret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxxxxxxxxxxxxxxxxxxxxxx'</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;">$friends</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;">friends_get</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;p&gt;Hello &lt;fb:name uid=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$user_id</span><span style="color: #000099; font-weight: bold;">\&quot;</span> useyou=<span style="color: #000099; font-weight: bold;">\&quot;</span>false<span style="color: #000099; font-weight: bold;">\&quot;</span> linked=<span style="color: #000099; font-weight: bold;">\&quot;</span>false<span style="color: #000099; font-weight: bold;">\&quot;</span> firstnameonly=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/fb:name&gt;, you have &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$friends</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$friend</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$infos</span><span style="color: #339933;">.=</span><span style="color: #000088;">$friend</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$infos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$infos</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$infos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gender</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;">$infos</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'sex'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$gender_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$gendervalue</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$gendervalue</span><span style="color: #009900;">&#91;</span>sex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$male</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>male<span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>male<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$gender_array</span><span style="color: #009900;">&#91;</span>female<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: #000088;">$female</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">-</span><span style="color: #000088;">$male</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&lt;li&gt;Males: <span style="color: #006699; font-weight: bold;">$male</span>%&lt;/li&gt;&lt;li&gt;Females: <span style="color: #006699; font-weight: bold;">$female</span>%&lt;/li&gt;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;has &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends. <span style="color: #006699; font-weight: bold;">$male</span><span style="color: #009933; font-weight: bold;">% o</span>f them are male. <span style="color: #006699; font-weight: bold;">$female</span>% are female&quot;</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>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;fb:prompt-permission perms=<span style="color: #000099; font-weight: bold;">\&quot;</span>publish_stream<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Publish results on your wall!!&lt;/fb:prompt-permission&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;">$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;">stream_publish</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</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></pre></td></tr></table></div>

<p>That is the same as <a href="http://www.emanueleferonato.com/2009/09/20/developing-a-facebook-application-for-absolute-beginners/">Developing a Facebook Application for absolute beginners</a> until <strong>line 33</strong><span id="more-1686"></span></p>
<p>So let&#8217;s take a look to the new lines:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;has &quot;</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;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; friends. <span style="color: #006699; font-weight: bold;">$male</span><span style="color: #009933; font-weight: bold;">% o</span>f them are male. <span style="color: #006699; font-weight: bold;">$female</span>% are female&quot;</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>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&lt;fb:prompt-permission perms=<span style="color: #000099; font-weight: bold;">\&quot;</span>publish_stream<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Publish results on your wall!!&lt;/fb:prompt-permission&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;">$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;">stream_publish</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>line 35</strong>: defining a simple message telling how many friends do you have</p>
<p><strong>line 37</strong>: checking if the user allowed the application to publish on the wall. When you run a Facebook application, it cannot interact with your profile doing actions such as writing on your wall or sending emails.</p>
<p>Facebook offers some API functionality that requires the user to specifically opt in before your application or site can use that functionality. These methods are specific to certain use cases that require a greater level of trust from the user. Users express this trust by granting your application or site specific extended permissions.</p>
<p>The permission we need this time is <code>publish_stream</code> which lets your application post content, comments, and likes to a user&#8217;s profile and in the streams of the user&#8217;s friends without prompting the user.</p>
<p>You can check the whole list of permission at <a href="http://wiki.developers.facebook.com/index.php/Extended_application_permission" target = "_blank">this page</a></p>
<p><strong>line 40</strong>: if the user did not allow the application to publish, renders the content of the tag as a link that, when clicked, initiates a dialog requesting the specified extended permissions from the user.</p>
<p>This one:</p>
<p><img src="/images/fbapp02.png" alt="" /></p>
<p>Once you click on allow, and reload the application, the message at <strong>line 35</strong> will be published on your profile thanks to&#8230;</p>
<p><strong>line 43</strong>: <code>stream_publish</code> method publishes a post into the stream on the user&#8217;s or Facebook Page&#8217;s Wall and News Feed.</p>
<p>There are various options we&#8217;ll meet during next tutorials, but at the moment you are able to publish content on users profile.</p>
<p><a href="http://apps.facebook.com/genderz_demo/" target = "_blank">Take a look at the application</a>  and see how does it publish your friends gender stats on your profile.</p>
<p>Next time, we&#8217;ll add even more interaction.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/09/28/developing-a-facebook-application-for-absolute-beginners-step-2/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
