{"id":93,"date":"2011-06-23T19:33:29","date_gmt":"2011-06-23T19:33:29","guid":{"rendered":"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/?p=93"},"modified":"2011-06-24T09:19:07","modified_gmt":"2011-06-24T09:19:07","slug":"snippet-of-code-2-developing-facebook-apps","status":"publish","type":"post","link":"https:\/\/www.45rpmsoftware.com\/blog\/?p=93","title":{"rendered":"Snippet of code #2 &#8211; Developing Facebook Apps"},"content":{"rendered":"<p>A little while ago my sister approached me with an idea which requires a Facebook app. I&#8217;ve never written a Facebook app before, so I stocked up on books, read a little, and got stuck in.<\/p>\n<p>What a complete waste of time. \u00a0It seems that the Facebook development system is a little fluid. \u00a0Nothing I learned worked, and the books would have been more useful if I had used them as substitute loo roll. \u00a0<!--more-->I was not happy. \u00a0So I decided to approach this as a bodging challenge, and just muddle through. \u00a0What follows are my rough notes so that I can create a new Facebook app easily in future (prettied up a little so that they&#8217;re readable). \u00a0If you find them useful too then that&#8217;s wonderful. If you don&#8217;t then please let me know how I can improve them. \u00a0I make no promises that Facebook won&#8217;t change its procedures again, nor do I promise to notice if they do. \u00a0If you spot any anachronisms in these instructions, please let me know so that I can update them.<\/p>\n<p><strong><span style=\"font-family: Georgia, 'Bitstream Charter', serif; line-height: 24px; font-size: 16px;\">What you need to get started<\/span><\/strong><\/p>\n<ol>\n<li>a web site. The code for your app will be hosted on your own web site.a facebook account just for mucking about with. \u00a0Some say that you can muck up your &#8216;real&#8217; account by developing on it, where &#8216;muck up&#8217; means losing all your contacts. \u00a0I suspect that this might not apply with today&#8217;s Facebook developer tools, but I&#8217;m not about to take the risk.<\/li>\n<li>the Facebook developer app. \u00a0You can install the Facebook developer app by visiting <a title=\"Facebook Developer\" href=\"https:\/\/www.facebook.com\/developers\/\">https:\/\/www.facebook.com\/developers\/<\/a> and clicking &#8216;Set Up New App&#8217;. Tutorials are available at <a title=\"Facebook tutorial\" href=\"http:\/\/developers.facebook.com\/docs\/\">http:\/\/developers.facebook.com\/docs\/<\/a> but they didn&#8217;t seem to help me much or, indeed, work.<\/li>\n<li>a sense of humour. \u00a0I&#8217;ve found so many dead links on the Facebook developer site that I almost wonder if they&#8217;re considering phasing out the technology. Plough on. \u00a0You&#8217;ll get there in the end.<\/li>\n<\/ol>\n<p><strong><span style=\"font-family: Georgia, 'Bitstream Charter', serif; line-height: 24px; font-size: 16px;\">What I&#8217;ve assumed<\/span><\/strong><\/p>\n<ol>\n<li><span style=\"font-family: Georgia, 'Bitstream Charter', serif; line-height: 24px; font-size: 16px;\">you&#8217;re familiar with HTML and PHP.<\/span>you know your way around Facebook.<\/li>\n<li>you&#8217;ve got a good text editor (I like <a title=\"TextWrangler\" href=\"http:\/\/www.barebones.com\/products\/textwrangler\/\">TextWrangler<\/a>)\u2026<\/li>\n<li>\u2026and a good FTP package (I&#8217;m using <a title=\"Panic Transmit\" href=\"http:\/\/www.panic.com\/transmit\/\">Transmit<\/a> at the moment).<\/li>\n<\/ol>\n<p><strong>Getting Started<\/strong><\/p>\n<p>If you haven&#8217;t already done so, set up your first app by visiting <a title=\"Facebook Developer\" href=\"https:\/\/www.facebook.com\/developers\/\">Facebook Developer<\/a> and clicking &#8216;Set Up New App&#8217;. \u00a0If you&#8217;ve done this already, perhaps when attempting to create another app, you can get back to the Facebook develop app by clicking &#8216;Apps&#8217; in the left hand bar, and then clicking on the Developer app.<\/p>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.38.47.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-94\" title=\"Screen shot 2011-06-22 at 20.38.47\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.38.47.png\" alt=\"\" width=\"431\" height=\"259\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.38.47.png 431w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.38.47-300x180.png 300w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/a><\/p>\n<p>Accessing the Developer app in this manner will display a list of Apps that you&#8217;re working on, and information that the Facebook guys think will be of interest to you.<\/p>\n<hr \/>\n<p style=\"text-align: center;\"><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.38.47.png\"><\/a><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.36.03.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-96\" title=\"Screen shot 2011-06-22 at 20.36.03\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.36.03.png\" alt=\"\" width=\"522\" height=\"206\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.36.03.png 522w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.36.03-300x118.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/a><\/p>\n<p>You now have the opportunity to name your App. \u00a0Your App name doesn&#8217;t have to be all one word &#8211; you can have spaces, numbers and (I think) some punctuation. \u00a0You&#8217;ll also need to agree to the Facebook terms and conditions. \u00a0It&#8217;s just the standard stuff really, sell your soul to Mark Zuckerberg etc etc. Once you&#8217;ve agreed, you&#8217;ll need to pass a CAPTCHA security check &#8211; just to prove that you&#8217;re human.\u00a0I passed &#8211; although I&#8217;m still not entirely certain how.<\/p>\n<hr \/>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.50.42.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-97\" title=\"Screen shot 2011-06-22 at 20.50.42\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.50.42.png\" alt=\"\" width=\"730\" height=\"332\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.50.42.png 730w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.50.42-300x136.png 300w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/a><\/p>\n<p>Once you&#8217;ve passed the humanity check, you&#8217;ll be presented with a form covering various aspects of your App. \u00a0I&#8217;m going to ignore it. \u00a0It&#8217;s not code, so I&#8217;m not very interested. Doubtless, when I get more experienced, I might play with this form at this stage &#8211; but for now I&#8217;m going to save it for later. \u00a0For now, click &#8216;Back to My Apps&#8217;<\/p>\n<hr \/>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.53.50.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-98\" title=\"Screen shot 2011-06-22 at 20.53.50\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.53.50.png\" alt=\"\" width=\"740\" height=\"485\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.53.50.png 740w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-20.53.50-300x196.png 300w\" sizes=\"(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<p>You&#8217;ll now see a screen listing all the Apps that you&#8217;ve created in Facebook. \u00a0If you&#8217;ve created more than one, click on the one that you&#8217;re using for this tutorial in the left hand bar.<\/p>\n<p>Take a note of the Application ID and the App secret. \u00a0You&#8217;ll need this for your code.<\/p>\n<hr \/>\n<p>Having done this, you will now need to download some pre-prepared files from Facebook. \u00a0These are all conveniently zipped up and the instructions for downloading them can be found by clicking the &#8216;Get started quickly with some example code!&#8217; link. \u00a0It all seems very *nix heavy. \u00a0I approve!<\/p>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.09.27.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-99\" title=\"Screen shot 2011-06-22 at 21.09.27\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.09.27.png\" alt=\"\" width=\"676\" height=\"279\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.09.27.png 676w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.09.27-300x123.png 300w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><\/a><\/p>\n<p>Most of this we can ignore quite safely. \u00a0In fact, the only bit that I care about is in the \/src directory.<\/p>\n<hr \/>\n<p>In the interests of neatness, you will also need to create an include.php file containing your secret and your API key. \u00a0Mine looks like this:<\/p>\n<pre>&lt;?php\r\nrequire_once '.\/src\/facebook.php';\r\n\r\n\/\/ Create our Application instance.\r\n$facebook = new Facebook(array(\r\n   'appId' =&gt; '239896462690066',\r\n   'secret' =&gt; '88bea00374e6bb16b788752f1172d395',\r\n   'cookie' =&gt; true,\r\n));\r\n?&gt;<\/pre>\n<p>Going through it line by line:<\/p>\n<p>The require_once tells our program to include the facebook.php code. If you try to re-include facebook.php later then it won&#8217;t be &#8211; because you only require it to load once. Natch. The path that you use depends on how you&#8217;ve laid out your website. \u00a0I&#8217;m not going to explain how paths work here &#8211; if you don&#8217;t know then O&#8217;Reilly do some very good books on learning Unix.<\/p>\n<p>The &#8216;new Facebook&#8217; is an instruction to instantiate a new Facebook app, using the credentials supplied. \u00a0The cookie parameter allows it to create a cookie on the users hard drive.<\/p>\n<hr \/>\n<p>Finally, you will need to create the code for your app. \u00a0The root for this will always be called index.php. \u00a0In the interests of keeping this tutorial simple, I&#8217;ve just created a &#8220;Hello World&#8221; app. \u00a0Imaginative, no?<\/p>\n<pre>&lt;?php\r\nrequire_once 'include.php';\r\n?&gt;\r\n&lt;h1&gt;Hello World&lt;\/h1&gt;<\/pre>\n<hr \/>\n<p>Having created these files, upload them to the directory of choice on your website using your favourite FTP program. \u00a0I used to be a fan of <a title=\"CyberDuck\" href=\"http:\/\/cyberduck.ch\/\">Cyberduck<\/a> (free), but now I&#8217;m a heavy <a title=\"Transmit\" href=\"http:\/\/www.panic.com\/transmit\/\">Transmit<\/a> user. \u00a0After uploading, my directory structure looks like this:<\/p>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.38.37.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-106\" title=\"Screen shot 2011-06-22 at 21.38.37\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.38.37.png\" alt=\"\" width=\"418\" height=\"163\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.38.37.png 418w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.38.37-300x116.png 300w\" sizes=\"(max-width: 418px) 100vw, 418px\" \/><\/a><\/p>\n<p>I have no idea what fb_ca_chain_bundle.crt is for. \u00a0I suppose I might find out later. \u00a0It&#8217;s a certificate &#8211; but more than that I cannot say.<\/p>\n<hr \/>\n<p>Now return to the Facebook developer app. \u00a0Click on the Edit Settings link, and then the &#8216;Facebook Integration&#8217; link.<\/p>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.51.58.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-107\" title=\"Screen shot 2011-06-22 at 21.51.58\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.51.58.png\" alt=\"\" width=\"521\" height=\"309\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.51.58.png 521w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.51.58-300x177.png 300w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/a><\/p>\n<p>You&#8217;ll need to fill in Canvas URL (because that&#8217;s the link to the code that you&#8217;ve just written). \u00a0You&#8217;ll also need to give your App a unique Facebook URL &#8211; this name doesn&#8217;t refer to any page or code that you&#8217;ve created already. \u00a0With the unique Facebook URL you aren&#8217;t allowed anything other than lowercase letters. \u00a0If you provide an invalid name then the Facebook developer app with respond with a bunch of error messages. \u00a0Work through them and eventually your App will be created successfully.<\/p>\n<hr \/>\n<p><a href=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.56.14.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-110\" title=\"Screen shot 2011-06-22 at 21.56.14\" src=\"http:\/\/62.253.218.153\/~rpmsoft\/45rpmdump\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.56.14.png\" alt=\"\" width=\"529\" height=\"352\" srcset=\"https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.56.14.png 529w, https:\/\/www.45rpmsoftware.com\/blog\/wp-content\/uploads\/2011\/06\/Screen-shot-2011-06-22-at-21.56.14-300x199.png 300w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/a><\/p>\n<p>Once your App has been created, return to the Facebook Developer app. \u00a0Click on the Edit Settings link, and then the &#8216;Facebook Integration&#8217; link. \u00a0You may need to fill in, or correct, the Tab URL &#8211; and you&#8217;ll definitely need to give your Tab a name. \u00a0Save your changes.<\/p>\n<hr \/>\n<p>Now. \u00a0The moment of truth. \u00a0Try to run your application. \u00a0You do this by returning to the Facebook developer app, but this time you&#8217;ll need to click on the Application Profile Page link. \u00a0At the top of the screen you will see a link encouraging you to &#8216;Go to app&#8217;. \u00a0Do it. This will run your App. \u00a0Hopefully it will work first time &#8211; but it may not. \u00a0In my case it didn&#8217;t because I needed to install the the CURL PHP extension. \u00a0If you&#8217;re in the same boat, install any missing extensions and then try again.<\/p>\n<p><strong>Useful Resources<\/strong><\/p>\n<p>Ignore the Facebook books. \u00a0They&#8217;re hopeless. \u00a0Facebook is evolving too fast for paper based media to keep up. \u00a0Instead, get yourself some good books on PHP, HTML and, if you want to muck around with data (you probably will), MySQL.<\/p>\n<p><strong>In Future<\/strong><\/p>\n<p>I am going to flesh out my app to be a little more useful. \u00a0As I do so I&#8217;ll add more to my Facebook notes. \u00a0So check back occasionally.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A little while ago my sister approached me with an idea which requires a Facebook app. I&#8217;ve never written a Facebook app before, so I stocked up on books, read a little, and got stuck in. What a complete waste of time. \u00a0It seems that the Facebook development system is a little fluid. \u00a0Nothing I &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.45rpmsoftware.com\/blog\/?p=93\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Snippet of code #2 &#8211; Developing Facebook Apps&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/93"}],"collection":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93"}],"version-history":[{"count":0,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.45rpmsoftware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}