<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Thinkdiff.net</title>
	
	<link>http://thinkdiff.net</link>
	<description>geeky stuff, facebook, linkedin, php, mysql &amp; more</description>
	<lastBuildDate>Wed, 04 Jan 2012 06:49:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/thinkdiff/IhBP" /><feedburner:info uri="thinkdiff/ihbp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Rewind 2011 &amp; Happy New Year 2012</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/eI5OmNphz9Y/</link>
		<comments>http://thinkdiff.net/personal/rewind-2011-happy-new-year-2012/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 06:30:10 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2498</guid>
		<description><![CDATA[Firstly I want to say sorry to my blog readers because I didn&#8217;t publish much article about facebook app development in 2011. Because I was very busy for my job, life and honestly said I was not an active facebook web developer in 2011. In computer science algorithm and data structure subject we learned &#8220;Time [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2012/01/my_iphone.jpg" rel="lightbox[2498]"><img class="alignleft  wp-image-2499" title="iPhone4" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2012/01/my_iphone.jpg" alt="iPhone4" width="173" height="200" /></a>Firstly I want to say sorry to my blog readers because I didn&#8217;t publish much article about facebook app development in 2011. Because I was very busy for my job, life and honestly said I was not an active facebook web developer in 2011. In computer science algorithm and data structure subject we learned &#8220;Time space trade off&#8221;. That means if you need faster solution you&#8217;ve to use more space and vice versa. This is happened in our life also. If you invest some time in a work you definitely have to  leave some time in other works.</p>
<p>Whatever I&#8217;m writing this post to inform my friends and blog readers about my activity in 2011</p>
<p><span id="more-2498"></span></p>
<ol>
<li>I had been doing web application development job (part time) via oDesk for a US client. I worked almost 1 year for him. I used <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> framework, <a href="http://www.mysql.com/products/workbench/" target="_blank">MySQL workbench</a>, <a href="http://www.springloops.com/v2/" target="_blank">SpringLoops</a>, and <a href="http://www.twilio.com/" target="_blank">Twilio Communication Service API</a> to integrate voice and sms in his project. We worked in a team and my role was managing the project and team, implementing API, make the web app structure, design database and deploy on server.</li>
<li>I joined in a Berkely based US company as a <strong>Sr. Software Engineer</strong> where my role was to <strong>manage and develop iOS application</strong>. But I left the job after 3 months. Its really tough to do job late at night, because there is a 12 hours difference between Bangladesh and US. So their morning is night in here.</li>
<li>In 2011, I was fully concentrated on Objective C, XCode and iOS applications development. That year was very successful for me. I learned many things of iOS game and application development. I learned <a href="http://en.wikipedia.org/wiki/Tile-based_game" target="_blank">Tile based game development</a>, <a href="http://box2d.org/" target="_blank">box2d</a> physics engine based game development and all about <a href="http://www.cocos2d-iphone.org/" target="_blank">cocos2d framework</a> based 2D game development. My wife all time supported me by designing graphics for my games and apps and providing continuous support. I published some major updates of some of my apps. The success is <a href="http://ithinkdiff.net" target="_blank">all of my free iOS apps</a> downloaded more than <strong>1 Million</strong> times via all iTunes Store. And people updated my free apps more than <strong>1.5 Million</strong> times. And the <strong>average feedback of my apps is 4.0 out of 5.0.</strong>The success was not come in a day. Sometimes I worked more than 16 hours in a day. And sometime I didn&#8217;t work any time <img src='http://c3354688.r88.cf0.rackcdn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>I also fully moved to <a href="https://github.com/mahmudahsan" target="_blank">github</a> for all of my public code hosting.</li>
<li>I updated my bike from <a href="http://bikeadvice.in/wp-content/uploads/2008/09/discover-135.jpg" target="_blank" rel="lightbox[2498]">Bajaj Discover</a> to <a href="http://www.flickr.com/photos/mahmudahsan/6593250981/in/photostream" target="_blank">Yamaha Fazer</a> during the middle of the year 2011.</li>
<li>I was thinking to join for higher study, and thinking to move Malaysia for my MSc. I attended <a href="http://www.ielts.org/" target="_blank">IELTS Academic Module exam </a>and achieved <strong>Band 6.5</strong> score<strong><em>(listning 6.5, Reading 6.5, Speaking 6.5 and Writing 5.5)</em></strong>. I was little surprised for my writing score and I realized that my academic writing is not good, so I&#8217;ve to improve it more :S</li>
<li>Near the end of the year I updated my camera from <a href="http://cdn-4.nikon-cdn.com/en_INC/IMG/Assets/Digital-SLR/2010/25452-Nikon-D5000/Views/25452_D5000_34l.png?targetMedia=/en_INC/IMG/Assets/Digital-SLR/2010/25452-Nikon-D5000/Views/353_25452_D5000_34l.png" target="_blank" rel="lightbox[2498]">Nikon D5000</a> to <a href="http://www.flickr.com/photos/mahmudahsan/6601865931/in/photostream" target="_blank">Canon 5D Mark II</a>.</li>
<li>And I&#8217;m consulting with a professor in Malayisa and looking for opportunity to join any university to study MSc by Research.</li>
</ol>
<p>I believe to spend time happily. And I all time try do that. And I&#8217;m very thankful to Allah (God) that he helped me by giving success.</p>
<p>In 2012, I still want to move Malaysia to complete my MSc by Research. Please pray for me. Additionally I&#8217;ll try to write more technical post in my blog. I&#8217;ve also some plan to develop some new iOS applications and games beside my part time Web application development job. I wish all of you a:</p>
<h2 style="text-align: center;"><span style="color: #800080;"><strong>Happy New Year</strong></span></h2>
<h2 style="text-align: center;"><span style="color: #800080;">2012</span></h2>

<p><a href="http://feedads.g.doubleclick.net/~a/HE_wR8mriutLJFKYLYiKaz3HlCc/0/da"><img src="http://feedads.g.doubleclick.net/~a/HE_wR8mriutLJFKYLYiKaz3HlCc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/HE_wR8mriutLJFKYLYiKaz3HlCc/1/da"><img src="http://feedads.g.doubleclick.net/~a/HE_wR8mriutLJFKYLYiKaz3HlCc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/eI5OmNphz9Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/personal/rewind-2011-happy-new-year-2012/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/personal/rewind-2011-happy-new-year-2012/</feedburner:origLink></item>
		<item>
		<title>Feed Dialog – Message field deprecated!!!</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/w4yW9JQCSnI/</link>
		<comments>http://thinkdiff.net/facebook/feed-dialog-message-field-deprecated/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 08:38:53 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[iPhone/iPad]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[message]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2487</guid>
		<description><![CDATA[I&#8217;ve an iOS application named Translator Free  where I have been using Facebook iOS library to share translated text as user&#8217;s facebook status. Some day ago I noticed that facebook deprecated the message field. They deprecated it in July 12, 2011 and I noticed it much later. I&#8217;m surprised for their decision. What&#8217;s the problem [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" rel="lightbox[2487]"><img class="alignleft size-full wp-image-2142" title="facebook" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" alt="facebook" width="200" height="150" /></a>I&#8217;ve an iOS application named <a href="http://ithinkdiff.net/reference/translator-free/" target="_blank">Translator Free</a>  where I have been using Facebook iOS library to share translated text as user&#8217;s facebook status. Some day ago I noticed that facebook deprecated the <a href="https://developers.facebook.com/docs/reference/dialogs/feed/" target="_blank"><strong>message</strong> field</a>. They deprecated it in July 12, 2011 and I noticed it much later. I&#8217;m surprised for their decision.</p>
<p><span id="more-2487"></span></p>
<p>What&#8217;s the problem if a person like to share pre-populated text as his status message. I don&#8217;t know why they took the decision!!</p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/11/message_deprected.jpg" rel="lightbox[2487]"><img class="aligncenter size-full wp-image-2488" title="message_deprected" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/11/message_deprected.jpg" alt="" width="625" height="266" /></a></p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/11/message_deprecate_2.jpg" rel="lightbox[2487]"><img class="aligncenter size-full wp-image-2489" title="message_deprecate_2" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/11/message_deprecate_2.jpg" alt="" width="599" height="449" /></a></p>
<p>So if you need to update user&#8217;s status using facebook iOS SDK you can do the following way:</p>
<p>&nbsp;</p>
<p>Instead of using the below code</p>
<pre class="brush: cpp; title: ; notranslate">
[facebook dialog:@&quot;feed&quot;
	 andParams:params
	 andDelegate:self];
</pre>
<p>Use the following solution</p>
<pre class="brush: cpp; title: ; notranslate">
 [facebook requestWithGraphPath:@&quot;me/feed&quot;
        andParams:params
        andHttpMethod:@&quot;POST&quot;
        andDelegate:self];
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/4j_4ra41tO_KLNx2GyKFpjvGH70/0/da"><img src="http://feedads.g.doubleclick.net/~a/4j_4ra41tO_KLNx2GyKFpjvGH70/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4j_4ra41tO_KLNx2GyKFpjvGH70/1/da"><img src="http://feedads.g.doubleclick.net/~a/4j_4ra41tO_KLNx2GyKFpjvGH70/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/w4yW9JQCSnI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/facebook/feed-dialog-message-field-deprecated/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/facebook/feed-dialog-message-field-deprecated/</feedburner:origLink></item>
		<item>
		<title>How to Develop &amp; Test Facebook Connect Application Locally</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/24v6dXrgFRg/</link>
		<comments>http://thinkdiff.net/facebook/how-to-develop-test-facebook-connect-application-locally/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 20:16:53 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[locally]]></category>
		<category><![CDATA[mamp]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[virtual host]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2474</guid>
		<description><![CDATA[Most of the time people write code locally, upload them in remote server and test whether his facebook connect base application works or not. They either has a domain name or a dedicated IP address. Because when we create a facebook application we have to provide an URL in the setting page. In this tutorial [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" rel="lightbox[2474]"><img class="alignleft size-full wp-image-2142" title="facebook" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" alt="facebook" width="200" height="150" /></a>Most of the time people write code locally, upload them in remote server and test whether his facebook connect base application works or not. They either has a domain name or a dedicated IP address. Because when we create a facebook application we have to provide an URL in the setting page. In this tutorial I&#8217;ll show you how to develop and test facebook connect base application locally. This tutorial will only work for facebook connect base application or website, not for facebook Iframe base canvas or page application.</p>
<p><strong>Case:</strong></p>
<ol>
<li>We want to develop a facebook connect base website/application</li>
<li>We want to test everything in our laptop or local pc not on the remote server</li>
<li>Suppose we don&#8217;t have a dedicated IP address or any domain</li>
</ol>
<p><span id="more-2474"></span></p>
<p>I assume that you&#8217;re using mac (as I do), if you&#8217;re using linux or windows then you&#8217;ve to learn how to create virtual host in your local pc.</p>
<p><strong>Solution:</strong></p>
<p><strong>Step 1:</strong></p>
<p>To learn how to develop facebook connect base application checkout the following tutorial</p>
<ol>
<li><a href="http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/" target="_blank">PHP SDK 3.0 &amp; Graph API base Facebook Connect Tutorial</a></li>
<li><a href="http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/" target="_blank">New JavaScript SDK &amp; OAuth 2.0 based FBConnect Tutorial</a></li>
</ol>
<p><strong>Step 2:</strong></p>
<p>Create a virtual host in your pc. I&#8217;m using <a href="http://www.mamp.info/en/mamp-pro/" target="_blank">MAMP Pro </a>its super easy for mac to create virtual host using this tool. I created a virtual host named fblatestphotos.com in my local pc. You&#8217;ve to also set the local folder where you&#8217;ll store file for this host. After successfully setup everything you&#8217;ve to click apply then the apache server will restart. Now I can browse http://fblatestphotos.com:8888/ successfully in my pc.</p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/09/mamp_pro.jpg" rel="lightbox[2474]"><img class="aligncenter size-full wp-image-2479" title="MAMP Pro" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/09/mamp_pro.jpg" alt="" width="583" height="515" /></a></p>
<p>If you use other operating system or different tool please google and explore how to create virtual host in your local pc.</p>
<p><strong>Step 3:</strong></p>
<p>Now create a facebook application or use your old facebook application and change the setting. In the <strong>Site URL</strong> field set the local virtual hosting address, in my case it is http://fblatestphotos.com:8888/</p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/09/facebook-app-setting.jpg" rel="lightbox[2474]"><img class="aligncenter size-full wp-image-2480" title="facebook-app-setting" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/09/facebook-app-setting.jpg" alt="" width="596" height="481" /></a></p>
<p><strong>Step 4:</strong></p>
<p>Now follow <strong>step 1</strong> and download any of the source code from the tutorials of <strong>Step 1</strong>, move the code in the local folder that you&#8217;re using as the virtual host folder. Then update the<strong> App ID</strong> and/or <strong>App Secret</strong> in the config file of the source code.</p>
<p>If you do everything successfully then you should able to test the application successfully in your local pc. And it saves lots of time as you&#8217;ll test locally. Additionally if you don&#8217;t have dedicated IP or domain you don&#8217;t have to worry as you could test application locally now. Hope it helps.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/1qDOhxcA14v4D2SsZX8t8Us9lH0/0/da"><img src="http://feedads.g.doubleclick.net/~a/1qDOhxcA14v4D2SsZX8t8Us9lH0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/1qDOhxcA14v4D2SsZX8t8Us9lH0/1/da"><img src="http://feedads.g.doubleclick.net/~a/1qDOhxcA14v4D2SsZX8t8Us9lH0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/24v6dXrgFRg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/facebook/how-to-develop-test-facebook-connect-application-locally/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/facebook/how-to-develop-test-facebook-connect-application-locally/</feedburner:origLink></item>
		<item>
		<title>200+ ACM Problems solution source code</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/S5Xrpn7AIis/</link>
		<comments>http://thinkdiff.net/personal/200-acm-problems-solution-source-code/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 13:52:50 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[acm]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[data structure]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2460</guid>
		<description><![CDATA[During 2003~2007 I was an undergraduate computer science student. In this time for our course material and for programming passion I used to try to solve ACM problems from the well-known University of Valladolid site. I solved arround 203 ACM problems in this site. Today I found in my laptop still the accepted codes are [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/Icpc_logo.png" rel="lightbox[2460]"><img class="alignleft size-full wp-image-2461" title="ACM" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/Icpc_logo.png" alt="ACM" width="169" height="169" /></a>During 2003~2007 I was an undergraduate computer science student. In this time for our course material and for programming passion I used to try to solve ACM problems from the well-known <a href="http://acm.uva.es/problemset/" target="_blank">University of Valladolid site</a>. I solved arround 203 ACM problems in this site. Today I found in my laptop still the accepted codes are saved. So I think I should share these code. May be these could be useful for someone. I had written 99% of my code using C++ language.</p>
<p><span id="more-2460"></span></p>
<p>One thing I want to mention these codes are accepted but not the best optimized code. These codes were written by me during my student life so you can&#8217;t expect that also.</p>
<p>In my sharing code repository all the <strong>file names</strong> are the problem number from the <a href="http://acm.uva.es/problemset/" target="_blank">University of Valladolid site.</a> In valladolid site <a href="http://acm.uva.es/problemset/usersnew.php?user=38871" target="_blank">author statistics </a>is down, you can&#8217;t see anyone&#8217;s statistics but fortunately i saved my statistics in 2007 and <a href="http://thinkdiff.net/demo/Mahmud.htm" target="_blank">here it is</a>.</p>
<p><a href="https://github.com/mahmudahsan/203-ACM-Problems-Code" target="_blank"><img class="size-full wp-image-2403 aligncenter" title="Download Code" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/download_code.jpg" alt="Download Code" width="270" height="85" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/T1dQTjGK39es6Vpu3AxoNwaie70/0/da"><img src="http://feedads.g.doubleclick.net/~a/T1dQTjGK39es6Vpu3AxoNwaie70/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/T1dQTjGK39es6Vpu3AxoNwaie70/1/da"><img src="http://feedads.g.doubleclick.net/~a/T1dQTjGK39es6Vpu3AxoNwaie70/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/S5Xrpn7AIis" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/personal/200-acm-problems-solution-source-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/personal/200-acm-problems-solution-source-code/</feedburner:origLink></item>
		<item>
		<title>Facebook Open Graph Meta WordPress Plugin</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/x6QZ0a8m9S8/</link>
		<comments>http://thinkdiff.net/facebook/facebook-open-graph-meta-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 18:21:16 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[facebook like]]></category>
		<category><![CDATA[facebook open graph]]></category>
		<category><![CDATA[facebook share]]></category>
		<category><![CDATA[og]]></category>
		<category><![CDATA[open graph meta]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2379</guid>
		<description><![CDATA[Have you ever noticed that, if you implemented Facebook like or Facebook Share in wordpress blog and when people click Like the shared post on user wall looks not good most of the time. This is because you didn&#8217;t implement the facebook open graph meta data in your blog post or page. As a result [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/fb_open_graph.jpg" rel="lightbox[2379]"><img class="alignleft size-full wp-image-2382" title="fb_open_graph" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/fb_open_graph.jpg" alt="" width="172" height="172" /></a>Have you ever noticed that, if you implemented <strong>Facebook like</strong> or <strong>Facebook Share</strong> in wordpress blog and when people click <strong>Like</strong> the shared post on user wall looks not good most of the time. This is because you didn&#8217;t implement the <a href="http://developers.facebook.com/docs/opengraph/" target="_blank">facebook open graph meta</a> data in your blog post or page. As a result when facebook parse the link sometimes they can&#8217;t parse it properly that you expected.</p>
<p>To solve the situation you&#8217;ve to add open graph meta data in your site. Some days ago I manually added this in my blog&#8217;s theme, but later I decided to make a wordpress plugin so that it become easier to use and share with others.</p>
<p><span id="more-2379"></span></p>
<p><strong>My plugin features:</strong></p>
<p>1. Automatically set facebook open graph meta data in your wordpress site<br />
2. Open graph meta data will be dynamic based on post or page<br />
3. In the admin panel you can provide AppId<br />
4. In the admin panel you can provide facebook user id (admins)<br />
5. You can set a default image that will be used when there is no image associated with a post or page<br />
6. In the plugin admin page, you&#8217;ll see detailed specification to setup facebook app.</p>
<p style="text-align: center;"><a href="http://wordpress.org/extend/plugins/facebook-open-graph-meta/" target="_blank"><img class="aligncenter size-full wp-image-2400" title="download_plugin" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/download_plugin.jpg" alt="Download" width="270" height="85" /></a></p>
<p><strong>Plugin setting page</strong></p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/screen1.jpg" rel="lightbox[2379]"><img class="aligncenter size-full wp-image-2389" title="Setting Page" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/screen1.jpg" alt="" width="577" height="303" /></a></p>
<p><em>You will see detailed tutorial about how to set facebook application and retrieve the information in the plugin setting page.</em></p>
<p>If you activate this plugin you&#8217;ll see when people share or like your wordpress post or page, that will show nicely on their facebook walls. Thus user&#8217;s friends will be inspired to click the link.</p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/590x300.jpg" rel="lightbox[2379]"><img class="aligncenter size-full wp-image-2383" title="facebook wall post" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/590x300.jpg" alt="" width="575" height="292" /></a></p>
<p>After successfully installed the plugin and changed the html tag by yourself, if you view the source code of your blog page/post from browser you&#8217;ll notice the following things:<br />
HTML tag is changed</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot; xmlns:og=&quot;http://opengraphprotocol.org/schema/&quot; dir=&quot;ltr&quot; lang=&quot;en-US&quot;&gt;
</pre>
<p>Open graph meta data added</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- Facebook Open Graph --&gt;
&lt;meta property=&quot;fb:app_id&quot; content=&quot;XXXXXXXXXXX&quot; /&gt;
&lt;meta property=&quot;fb:admins&quot; content=&quot;YYYYYYYYYYY&quot; /&gt;
&lt;meta property=&quot;og:url&quot; content=&quot;http://thinkdiff.net/facebook/sharekit-must-have-ios-app-share-library/&quot;/&gt;
&lt;meta property=&quot;og:site_name&quot; content=&quot;Thinkdiff.net&quot; /&gt;
&lt;meta property=&quot;og:description&quot; content=&quot;geeky stuff, facebook, twitter, linkedin, php, mysql, web development, tips and more&quot; /&gt;

&lt;meta property=&quot;og:type&quot; content=&quot;website&quot; /&gt;
&lt;meta property=&quot;og:image&quot; content=&quot;http://thinkdiff.net/image/thinkdiff.net_splash.jpg&quot; /&gt;
</pre>
<p>Where XXX&#8230; and YYY&#8230; should be your app id and admin user id.</p>
<p style="text-align: center;">Hope this helps <img src='http://c3354688.r88.cf0.rackcdn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p><a href="http://feedads.g.doubleclick.net/~a/7p2kOe4DtBVgfYPXxitU83LFbAU/0/da"><img src="http://feedads.g.doubleclick.net/~a/7p2kOe4DtBVgfYPXxitU83LFbAU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7p2kOe4DtBVgfYPXxitU83LFbAU/1/da"><img src="http://feedads.g.doubleclick.net/~a/7p2kOe4DtBVgfYPXxitU83LFbAU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/x6QZ0a8m9S8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/facebook/facebook-open-graph-meta-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/facebook/facebook-open-graph-meta-wordpress-plugin/</feedburner:origLink></item>
		<item>
		<title>Replacing CodeIgniter’s session by PHP’s Native Session</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/36v4ahencXc/</link>
		<comments>http://thinkdiff.net/php/replacing-codeigniters-session-by-phps-native-session/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 17:27:48 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[native session]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2357</guid>
		<description><![CDATA[For last 8 months, I have been working on a web application. We are developing the application based on CodeIgniter framework. In our project there are normal web version and mobile view version. Some days ago we noticed that, some people can&#8217;t login their account via mobile version though there username &#38; password are correct. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/codeigniter.jpg" rel="lightbox[2357]"><img class="alignleft size-full wp-image-2358" title="codeigniter" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/08/codeigniter.jpg" alt="codeigniter" width="176" height="177" /></a>For last 8 months, I have been working on a web application. We are developing the application based on <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> framework. In our project there are normal web version and mobile view version. Some days ago we noticed that,<strong> some people can&#8217;t login</strong> their account <strong>via mobile version though there username &amp; password are correct</strong>. After debugging and digging the problem we found that in <strong>iPod Touch 2G/3GS Safari browser</strong>, this problem is happening.</p>
<p><span id="more-2357"></span></p>
<p>We are using CodeIgniter&#8217;s built in session library and that is different than normal PHP&#8217;s session. We found that for each visit of the user, <strong>the server can&#8217;t track the session and regenerating new session id each time</strong>. Very weird situation for us. As we coded all over based on CodeIginter&#8217;s session library&#8217;s function so its not optimal solution for us to remove the codes and use PHP&#8217;s native session. Because in that case there is high possibility to generate new bugs. After lots of searching in the net at last we found a wrapper class for CodeIgniter.</p>
<p>This wrapper class is named <a href="http://codeigniter.com/wiki/Native_session/" target="_blank">Native session </a>. It uses the same functions name like CodeIgniter&#8217;s Session class, but it used PHP&#8217;s native session on the back end. As our project is running on Dedicated Server so we are not worried about the session security. We replaced CodeIgniter&#8217;s Session class by this <a href="http://codeigniter.com/wiki/Native_session/" target="_blank">Native session</a>  class and it solved our problem.</p>
<p>So if you&#8217;re facing this type of session related problem by using CodeIgniter&#8217;s Session library, you can use the  <a href="http://codeigniter.com/wiki/Native_session/" target="_blank">Native session </a> library to fix the problem. Hope it helps.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/jT26lVvw9J1Qqj9Lt_zkD6uJcZM/0/da"><img src="http://feedads.g.doubleclick.net/~a/jT26lVvw9J1Qqj9Lt_zkD6uJcZM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/jT26lVvw9J1Qqj9Lt_zkD6uJcZM/1/da"><img src="http://feedads.g.doubleclick.net/~a/jT26lVvw9J1Qqj9Lt_zkD6uJcZM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/36v4ahencXc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/php/replacing-codeigniters-session-by-phps-native-session/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/php/replacing-codeigniters-session-by-phps-native-session/</feedburner:origLink></item>
		<item>
		<title>New JavaScript SDK &amp; OAuth 2.0 based FBConnect Tutorial</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/He-HicaNom0/</link>
		<comments>http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 09:47:58 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[oauth 2.0]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2323</guid>
		<description><![CDATA[Today Facebook released their updated JavaScript SDK. Now the authentication system is based on OAuth 2.0 and HTTPS. So I updated my previous tutorial by writing this new post. In this post I&#8217;ll show you using javascript how could you easily integrate facebook connect (login/logout) features in your site. Additionally how to use Facebook API [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" rel="lightbox[2323]"><img class="alignleft size-full wp-image-2142" title="facebook" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" alt="facebook" width="200" height="150" /></a>Today Facebook released their <a href="http://developers.facebook.com/blog/post/525/" target="_blank">updated JavaScript SDK</a>. Now the authentication system is based on OAuth 2.0 and HTTPS. So I updated my <a href="http://thinkdiff.net/facebook/graph-api-javascript-base-facebook-connect-tutorial/" target="_blank">previous tutorial </a>by writing this new post. In this post I&#8217;ll show you using javascript how could you easily integrate facebook connect (login/logout) features in your site. Additionally how to use Facebook API to get user&#8217;s information. Here I only used JavaScript no back-end PHP or any server side language.</p>
<p><span style="text-decoration: underline;"><strong>In this tutorial I&#8217;ll explain:</strong></span></p>
<ol>
<li>Facebook Authentication Process</li>
<li>Facebook new JavaScript Usage</li>
<li>Facebook Connect Authentication</li>
<li>How to get extended permission to get more informations</li>
<li>How to use graph api</li>
<li>How to show stream publish prompt and share prompt</li>
<li>How to publish post in user&#8217;s wall using graph api</li>
<li>How to get additional information by FQL Query</li>
<li>How to set status using old legacy api (REST api) calling</li>
<li>How to show ajax loader when interactive with facebook</li>
</ol>
<p><span id="more-2323"></span></p>
<p><strong>Before proceeding:<br />
<a href="http://thinkdiff.net/demo/newfbconnect1/jssdkouth2.html" target="_blank"><img class="size-full wp-image-2402 alignnone" title="Demo App" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/demo_application.jpg" alt="Demo App" width="270" height="85" /></a><a href="https://github.com/mahmudahsan/New-JavaScript-SDK---OAuth-2.0-based-FBConnect-Tutorial" target="_blank"><img class="size-full wp-image-2403 alignnone" title="Download Code" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/download_code.jpg" alt="" width="270" height="85" /></a> </strong></p>
<h2>1.    Facebook Authentication Process</h2>
<p>This is how facebook authorization process will work. We will follow this process in code.<br />
<a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/fb_authorization_thinkdiff.net_.jpg" rel="lightbox[2323]"><img class="aligncenter size-full wp-image-2328" title="fb_authorization_thinkdiff.net" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/fb_authorization_thinkdiff.net_.jpg" alt="" width="552" height="673" /></a></p>
<h2>2.    Facebook new JavaScript Usage</h2>
<p>So in the figure you are seeing how authentication will work in your site. Now we will implement that. Firstly you’ve to setup a facebook application to get the application id. You can <a href="http://developers.facebook.com/setup/" target="_blank">setup application from here</a>. Or if you have already setup a facebook application then just copy the application id and replace with xxxxxxxxxxx. Remember <strong>oauth: true</strong> is new addition in this latest javascript sdk that enables your site for OAuth 2.0 authentication.</p>
<pre class="brush: jscript; title: ; notranslate">
window.fbAsyncInit = function() {
        FB.init({ appId: 'Your_APP_ID',
            status: true,
            cookie: true,
            xfbml: true,
            oauth: true});

        showLoader(true);

        function updateButton(response) {
            button       =   document.getElementById('fb-auth');
            userInfo     =   document.getElementById('user-info');

            if (response.authResponse) {
                //user is already logged in and connected
                FB.api('/me', function(info) {
                    login(response, info);
                });

                button.onclick = function() {
                    FB.logout(function(response) {
                        logout(response);
                    });
                };
            } else {
                //user is not connected to your app or logged out
                button.innerHTML = 'Login';
                button.onclick = function() {
                    showLoader(true);
                    FB.login(function(response) {
                        if (response.authResponse) {
                            FB.api('/me', function(info) {
                                login(response, info);
                            });
                        } else {
                            //user cancelled login or did not grant authorization
                            showLoader(false);
                        }
                    }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});
                }
            }
        }

        // run once with current status and whenever the status changes
        FB.getLoginStatus(updateButton);
        FB.Event.subscribe('auth.statusChange', updateButton);
    };
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol
            + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
</pre>
<p>This is the most efficient way to load the javascript SDK in your web site. And in this way the sdk will load asynchronously so it does not block loading other elements of your page. <a href="http://developers.facebook.com/docs/reference/javascript/FB.init" target="_blank">Details of FB.init method</a>.</p>
<p>And your html tag should be</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html xmlns:fb=&quot;https://www.facebook.com/2008/fbml&quot;&gt;
</pre>
<h2>3.    Facebook Connect Authentication</h2>
<p>On the first part of the code you will see 2 Facebook api functions called</p>
<pre class="brush: jscript; title: ; notranslate">
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
</pre>
<p>After loading the facebook javascript library, this method <strong>getLoginStatus()</strong> called and checked the user authentication status and it will send the response to <strong>updateButton()</strong> method.</p>
<p><strong>FB.Event.subscribe()</strong> this method registered the <strong>auth.statusChange</strong> with facebook. That means if user successfully login or authorized your app or logout or cancel login process, it will trace that and call <strong>updateButton()</strong> method with the response. In this <strong>updateButton()</strong> method you&#8217;ll see the code of authentication that follows the first figure. In the full source code you&#8217;ll see 2 additional methods</p>
<pre class="brush: jscript; title: ; notranslate">
    function login(response, info){
        if (response.authResponse) {
            var accessToken                                =   response.authResponse.accessToken;

            userInfo.innerHTML                             = '&lt;img src=&quot;https://graph.facebook.com/' + info.id + '/picture&quot;&gt;' + info.name
                + &quot;&lt;br /&gt; Your Access Token: &quot; + accessToken;
            button.innerHTML                               = 'Logout';
            showLoader(false);
            document.getElementById('other').style.display = &quot;block&quot;;
        }
    }

    function logout(response){
        userInfo.innerHTML                             =   &quot;&quot;;
        document.getElementById('debug').innerHTML     =   &quot;&quot;;
        document.getElementById('other').style.display =   &quot;none&quot;;
        showLoader(false);
    }
</pre>
<p>Those are called when user successfully login and authorized your app and when user logout.</p>
<h2>4.    How to get extended permission to get more informations</h2>
<p>On the first part of the code you&#8217;ll see the code that will run when user click login.</p>
<pre class="brush: jscript; title: ; notranslate">
//user is not connected to your app or logged out
    button.innerHTML = 'Login';
    button.onclick = function() {
        showLoader(true);
        FB.login(function(response) {
            if (response.authResponse) {
                FB.api('/me', function(info) {
                    login(response, info);
                });
            } else {
                //user cancelled login or did not grant authorization
                showLoader(false);
            }
        }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});
    }
</pre>
<p>In this part you&#8217;ll see <strong>scope</strong> where you can provide extended permission parameters name. Don&#8217;t provide all permissions, only think which information you may need for your site. Here is <a href="http://developers.facebook.com/docs/reference/api/permissions/" target="_blank">details about permissions</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
{scope:'email,user_birthday,status_update,publish_stream,user_about_me'}
</pre>
<h2>5.    How to use graph api</h2>
<p>In the new javascript sdk, the authentication code is only changed, everything else remains same. To fully understand graph api <a href="http://developers.facebook.com/docs/api" target="_blank">visit the link </a>. Now i’ll show you, how to use graph api using javascript sdk. There is a method <a href="http://developers.facebook.com/docs/reference/javascript/FB.api" target="_blank">FB.api</a> . Using this method you can call <a href="http://developers.facebook.com/docs/api" target="_blank">graph api</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
FB.api('/me', function(response) {
  alert(response.name);
});
</pre>
<p>By calling this method it will show logged in user name. For another example check 7 number point.</p>
<h2>6.    How to show stream publish prompt and share prompt</h2>
<p>There is another javascript sdk method named <a href="http://developers.facebook.com/docs/reference/javascript/FB.ui" target="_blank">FB.ui</a>. Using the code you can prompt user for stream publish or share your page.</p>
<pre class="brush: jscript; title: ; notranslate">
function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
        showLoader(true);
        FB.ui(
        {
            method: 'stream.publish',
            message: '',
            attachment: {
                name: name,
                caption: '',
                description: (description),
                href: hrefLink
            },
            action_links: [
                { text: hrefTitle, href: hrefLink }
            ],
            user_prompt_message: userPrompt
        },
        function(response) {
            showLoader(false);
        });

    }

    function share(){
        showLoader(true);
        var share = {
            method: 'stream.share',
            u: 'http://thinkdiff.net/'
        };

        FB.ui(share, function(response) {
            showLoader(false);
            console.log(response);
        });
    }
</pre>
<p>You&#8217;ve to provide parameters when you call streamPublish() method.</p>
<pre class="brush: jscript; title: ; notranslate">
    function showStream(){
        FB.api('/me', function(response) {
            //console.log(response.id);
            streamPublish(response.name, 'I like the articles of Thinkdiff.net', 'hrefTitle', 'http://thinkdiff.net', &quot;Share thinkdiff.net&quot;);
        });
    }
</pre>
<h2>7.    How to publish post in user&#8217;s wall using graph api</h2>
<p>In my demo you’ll see another customized method named <strong>graphStreamPublish()</strong>. This is also a graph api example.</p>
<pre class="brush: jscript; title: ; notranslate">
function graphStreamPublish(){
        showLoader(true);

        FB.api('/me/feed', 'post',
        {
            message     : &quot;I love thinkdiff.net for facebook app development tutorials&quot;,
            link        : 'http://ithinkdiff.net',
            picture     : 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
            name        : 'iOS Apps &amp; Games',
            description : 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'

        },
        function(response) {
            showLoader(false);

            if (!response || response.error) {
                alert('Error occured');
            } else {
                alert('Post ID: ' + response.id);
            }
        });
    }
</pre>
<p>This method uses <strong>FB.api()</strong> and does a HTTP POST request to http://graph.facebook.com/me/feed url with some parameters to publish a feed on user&#8217;s wall.</p>
<h2>8.    How to get additional information by FQL Query</h2>
<p>Facebook Query Language  enables you to use a SQL-style interface to query the data exposed by the <a href="http://developers.facebook.com/docs/reference/api/" target="_blank">Graph API</a>. It provides for some advanced features not available in the Graph API, including batching multiple queries into a single call. <a href="http://developers.facebook.com/docs/reference/fql/" target="_blank">Checkout the tables </a>to know which data of facebook user you can retrieve. In the demo’s source code you’ll see</p>
<pre class="brush: jscript; title: ; notranslate">
function fqlQuery(){
        showLoader(true);

        FB.api('/me', function(response) {
            showLoader(false);

            //http://developers.facebook.com/docs/reference/fql/user/
            var query       =  FB.Data.query('select name, profile_url, sex, pic_small from user where uid={0}', response.id);
            query.wait(function(rows) {
                document.getElementById('debug').innerHTML =
                    'FQL Information: '+  &quot;&lt;br /&gt;&quot; +
                    'Your name: '      +  rows[0].name                                                            + &quot;&lt;br /&gt;&quot; +
                    'Your Sex: '       +  (rows[0].sex!= undefined ? rows[0].sex : &quot;&quot;)                            + &quot;&lt;br /&gt;&quot; +
                    'Your Profile: '   +  &quot;&lt;a href='&quot; + rows[0].profile_url + &quot;'&gt;&quot; + rows[0].profile_url + &quot;&lt;/a&gt;&quot; + &quot;&lt;br /&gt;&quot; +
                    '&lt;img src=&quot;'       +  rows[0].pic_small + '&quot; alt=&quot;&quot; /&gt;' + &quot;&lt;br /&gt;&quot;;
            });
        });
    }
</pre>
<h2>9. How to set status using old legacy api (REST api) calling</h2>
<p>You can still use the<a href="http://developers.facebook.com/docs/reference/rest/" target="_blank"> old legacy api</a>. In my demo you’ll see a text box, write something and click <strong>‘Status Set Using Legacy Api Call’ </strong>You’ll see your facebook status will update.</p>
<pre class="brush: jscript; title: ; notranslate">
function setStatus(){
        showLoader(true);

        status1 = document.getElementById('status').value;
        FB.api(
        {
            method: 'status.set',
            status: status1
        },
        function(response) {
            if (response == 0){
                alert('Your facebook status not updated. Give Status Update Permission.');
            }
            else{
                alert('Your facebook status updated');
            }
            showLoader(false);
        }
    );
}
</pre>
<h2>10. How to show ajax loader when interactive with facebook</h2>
<p>In the source code you will see a method <strong>showLoader()</strong>, and you&#8217;ll see several places of the source code this method is called.</p>
<pre class="brush: jscript; title: ; notranslate">
 function showLoader(status){
        if (status)
            document.getElementById('loader').style.display = 'block';
        else
            document.getElementById('loader').style.display = 'none';
    }
</pre>
<p><strong>Full Source Code of this project. Or direct <a href="https://github.com/mahmudahsan/New-JavaScript-SDK---OAuth-2.0-based-FBConnect-Tutorial" target="_blank">download from github</a><br />
</strong></p>
<div id="full_source_code" style="height: 400px; overflow: auto;">
<pre class="brush: jscript; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html xmlns:fb=&quot;https://www.facebook.com/2008/fbml&quot;&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/&gt;
        &lt;title&gt;New JavaScript SDK &amp; OAuth 2.0 based FBConnect Tutorial | Thinkdiff.net&lt;/title&gt;
        &lt;!--
            @author: Mahmud Ahsan (http://mahmud.thinkdiff.net)
        --&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;
            var button;
            var userInfo;

            window.fbAsyncInit = function() {
                FB.init({ appId: 'YOUR_APP_ID',
                    status: true,
                    cookie: true,
                    xfbml: true,
                    oauth: true});

               showLoader(true);

               function updateButton(response) {
                    button       =   document.getElementById('fb-auth');
                    userInfo     =   document.getElementById('user-info');

                    if (response.authResponse) {
                        //user is already logged in and connected
                        FB.api('/me', function(info) {
                            login(response, info);
                        });

                        button.onclick = function() {
                            FB.logout(function(response) {
                                logout(response);
                            });
                        };
                    } else {
                        //user is not connected to your app or logged out
                        button.innerHTML = 'Login';
                        button.onclick = function() {
                            showLoader(true);
                            FB.login(function(response) {
                                if (response.authResponse) {
                                    FB.api('/me', function(info) {
                                        login(response, info);
                                    });
                                } else {
                                    //user cancelled login or did not grant authorization
                                    showLoader(false);
                                }
                            }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});
                        }
                    }
                }

                // run once with current status and whenever the status changes
                FB.getLoginStatus(updateButton);
                FB.Event.subscribe('auth.statusChange', updateButton);
            };
            (function() {
                var e = document.createElement('script'); e.async = true;
                e.src = document.location.protocol
                    + '//connect.facebook.net/en_US/all.js';
                document.getElementById('fb-root').appendChild(e);
            }());

            function login(response, info){
                if (response.authResponse) {
                    var accessToken                                 =   response.authResponse.accessToken;

                    userInfo.innerHTML                             = '&lt;img src=&quot;https://graph.facebook.com/' + info.id + '/picture&quot;&gt;' + info.name
                                                                     + &quot;&lt;br /&gt; Your Access Token: &quot; + accessToken;
                    button.innerHTML                               = 'Logout';
                    showLoader(false);
                    document.getElementById('other').style.display = &quot;block&quot;;
                }
            }

            function logout(response){
                userInfo.innerHTML                             =   &quot;&quot;;
                document.getElementById('debug').innerHTML     =   &quot;&quot;;
                document.getElementById('other').style.display =   &quot;none&quot;;
                showLoader(false);
            }

            //stream publish method
            function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
                showLoader(true);
                FB.ui(
                {
                    method: 'stream.publish',
                    message: '',
                    attachment: {
                        name: name,
                        caption: '',
                        description: (description),
                        href: hrefLink
                    },
                    action_links: [
                        { text: hrefTitle, href: hrefLink }
                    ],
                    user_prompt_message: userPrompt
                },
                function(response) {
                    showLoader(false);
                });

            }
            function showStream(){
                FB.api('/me', function(response) {
                    //console.log(response.id);
                    streamPublish(response.name, 'I like the articles of Thinkdiff.net', 'hrefTitle', 'http://thinkdiff.net', &quot;Share thinkdiff.net&quot;);
                });
            }

            function share(){
                showLoader(true);
                var share = {
                    method: 'stream.share',
                    u: 'http://thinkdiff.net/'
                };

                FB.ui(share, function(response) {
                    showLoader(false);
                    console.log(response);
                });
            }

            function graphStreamPublish(){
                showLoader(true);

                FB.api('/me/feed', 'post',
                    {
                        message     : &quot;I love thinkdiff.net for facebook app development tutorials&quot;,
                        link        : 'http://ithinkdiff.net',
                        picture     : 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
                        name        : 'iOS Apps &amp; Games',
                        description : 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'

                },
                function(response) {
                    showLoader(false);

                    if (!response || response.error) {
                        alert('Error occured');
                    } else {
                        alert('Post ID: ' + response.id);
                    }
                });
            }

            function fqlQuery(){
                showLoader(true);

                FB.api('/me', function(response) {
                    showLoader(false);

                    //http://developers.facebook.com/docs/reference/fql/user/
                    var query       =  FB.Data.query('select name, profile_url, sex, pic_small from user where uid={0}', response.id);
                    query.wait(function(rows) {
                       document.getElementById('debug').innerHTML =
                         'FQL Information: '+  &quot;&lt;br /&gt;&quot; +
                         'Your name: '      +  rows[0].name                                                            + &quot;&lt;br /&gt;&quot; +
                         'Your Sex: '       +  (rows[0].sex!= undefined ? rows[0].sex : &quot;&quot;)                            + &quot;&lt;br /&gt;&quot; +
                         'Your Profile: '   +  &quot;&lt;a href='&quot; + rows[0].profile_url + &quot;'&gt;&quot; + rows[0].profile_url + &quot;&lt;/a&gt;&quot; + &quot;&lt;br /&gt;&quot; +
                         '&lt;img src=&quot;'       +  rows[0].pic_small + '&quot; alt=&quot;&quot; /&gt;' + &quot;&lt;br /&gt;&quot;;
                     });
                });
            }

            function setStatus(){
                showLoader(true);

                status1 = document.getElementById('status').value;
                FB.api(
                  {
                    method: 'status.set',
                    status: status1
                  },
                  function(response) {
                    if (response == 0){
                        alert('Your facebook status not updated. Give Status Update Permission.');
                    }
                    else{
                        alert('Your facebook status updated');
                    }
                    showLoader(false);
                  }
                );
            }

            function showLoader(status){
                if (status)
                    document.getElementById('loader').style.display = 'block';
                else
                    document.getElementById('loader').style.display = 'none';
            }

        &lt;/script&gt;

        &lt;h3&gt;New JavaScript SDK &amp; OAuth 2.0 based FBConnect Tutorial | Thinkdiff.net&lt;/h3&gt;
        &lt;button id=&quot;fb-auth&quot;&gt;Login&lt;/button&gt;
        &lt;div id=&quot;loader&quot; style=&quot;display:none&quot;&gt;
            &lt;img src=&quot;ajax-loader.gif&quot; alt=&quot;loading&quot; /&gt;
        &lt;/div&gt;
        &lt;br /&gt;
        &lt;div id=&quot;user-info&quot;&gt;&lt;/div&gt;
        &lt;br /&gt;
        &lt;div id=&quot;debug&quot;&gt;&lt;/div&gt;

        &lt;div id=&quot;other&quot; style=&quot;display:none&quot;&gt;
            &lt;a href=&quot;#&quot; onclick=&quot;showStream(); return false;&quot;&gt;Publish Wall Post&lt;/a&gt; |
            &lt;a href=&quot;#&quot; onclick=&quot;share(); return false;&quot;&gt;Share With Your Friends&lt;/a&gt; |
            &lt;a href=&quot;#&quot; onclick=&quot;graphStreamPublish(); return false;&quot;&gt;Publish Stream Using Graph API&lt;/a&gt; |
            &lt;a href=&quot;#&quot; onclick=&quot;fqlQuery(); return false;&quot;&gt;FQL Query Example&lt;/a&gt;

            &lt;br /&gt;
            &lt;textarea id=&quot;status&quot; cols=&quot;50&quot; rows=&quot;5&quot;&gt;Write your status here and click 'Status Set Using Legacy Api Call'&lt;/textarea&gt;
            &lt;br /&gt;
            &lt;a href=&quot;#&quot; onclick=&quot;setStatus(); return false;&quot;&gt;Status Set Using Legacy Api Call&lt;/a&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
</div>
<p>Additionally if you use <a href="http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development-php-sdk-3-0/" target="_blank">PHP SDK 3.0</a> or this new way of javascript sdk to authenticate your site you can enable oAuth Migration in the application setting.</p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/oauth_migration.jpg" rel="lightbox[2323]"><img class="aligncenter size-full wp-image-2334" title="oauth_migration" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/oauth_migration.jpg" alt="" width="553" height="440" /></a></p>
<p style="text-align: center;">Hope it will help you to understand new javascript sdk.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/-YI_HFHWq89PnDb3PqPZy6e8rTk/0/da"><img src="http://feedads.g.doubleclick.net/~a/-YI_HFHWq89PnDb3PqPZy6e8rTk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-YI_HFHWq89PnDb3PqPZy6e8rTk/1/da"><img src="http://feedads.g.doubleclick.net/~a/-YI_HFHWq89PnDb3PqPZy6e8rTk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/He-HicaNom0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/feed/</wfw:commentRss>
		<slash:comments>91</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/</feedburner:origLink></item>
		<item>
		<title>Beginning of my career</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/Jz7P06ED0w4/</link>
		<comments>http://thinkdiff.net/personal/beginning-of-my-career/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 16:34:15 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[career]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[mahmud]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2297</guid>
		<description><![CDATA[After long days I’m writing this post. Though my blog is very popular for facebook related tutorials, but this is not anything related to facebook or php. This is about me and beginning of my career. I think every programmer should learn different languages and work in different platforms. You can ask me why? If [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mahmud.thinkdiff.net" target="_blank"><img class="alignleft size-full wp-image-2305" title="mahmud-avatar" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/mahmud-avatar1.png" alt="" width="197" height="210" /></a>After long days I’m writing this post. Though my blog is very popular for facebook related tutorials, but this is not anything related to facebook or php. This is about me and beginning of my career.</p>
<p>I think every programmer should learn different languages and work in different platforms. You can ask me why? If you work on PHP backend development for 5 years, you will become an experienced guy and will earn better income.</p>
<p><strong>So why you’ll invest your time for other language and other platform?</strong><br />
Because it will give you a good taste of programming and you’ll enjoy yourself. I’m not telling you to leave PHP development and move to other platform, I’m just telling you to make some extra time from your regular job and work in different platform or technology.</p>
<p><span id="more-2297"></span></p>
<p><strong>In my student life I learned and worked on the following languages:</strong></p>
<h2>C, C++</h2>
<p>These were the first languages I learned in my student life. C is called the mother of all language. After learning C in the 2nd semester I learned C++. And I fall in love to the beauty of this language. I always submit ACM problem solutions using C++ and STL library of C++.</p>
<h2>Java 2</h2>
<p>In 5th semester I took this course in my study and I fall in love Java language also. I found many similarities between C++ and Java and most of the people told me that Java 2 actually copied OOP features from C++.</p>
<p>I was a fan of Java language in my student life, I still love Java but for last 3 years I didn’t work on any project of Java. I love Java so much that I read every page of “Java 2- The complete reference by Herbert Schildt and also “Java 2 How to program by Deitel &amp; Deitel” in my student life . I also read 3~4 books about j2me in my student life. In <strong>2007</strong> I created my own site <a title="FTechdb - j2me mobile phone applications" href="http://ftechdb.com" target="_blank">FTechdb.com</a> to sell my developed j2me mobile phone applications and I earned a good revenue from there. In <strong>2008</strong> when I completed my B.Sc of Computer Science  &amp; Engineering, nobody gave me a job for java. Even no once called me to interview for their company as a java developer.</p>
<p><strong>2 of my popular j2me applications:</strong></p>
<ol>
<li><a title="Smart Mobile Dictionary" href="http://ftechdb.com/mapps/show/1/1" target="_blank">Smart Mobile Dictionary</a></li>
<li><a title="Super Fx-Ball" href="http://ftechdb.com/mgames/show/1/1" target="_blank">Super FX-Ball</a>  (clone of popular dx ball game)</li>
</ol>
<h2>C#</h2>
<p>In my last semester <strong>2007</strong> my friend and me took a university project that we developed using C# language with related API. That was a SMS based desktop application. When we learned C# we found its completely copied the feature of Java with little twist. But whatever it gave us different taste of programming.</p>
<p><strong>About my professional career:</strong></p>
<h2>PHP, MySQL, JavaScript, HTML, CSS</h2>
<p>My professional career started as a web developer in <strong>2008</strong>, my salary was <strong>8000 BDT</strong> that means around <strong>100 USD per month</strong>. I was not happy about that salary but I had no choice, because no one gave me better job. I interviewed some well known software company in Dhaka like “<a href="http://tigeritbd.com/" target="_blank">Tiger IT BD</a>” but I was refused. Whatever, I took that small salary job and I was feeling a pressure to earn more. Why? Because I need good income to marry my lover. So I became very serious and was learning PHP, MySQL, JavaScript, HTML, CSS, CodeIgniter framework, jQuery library everything related to Web. And finally I took decision to participate Zend Certification exam, so I prepared myself and passed the exam <strong>May 5th, 2008</strong> and became a <a href="http://www.zend.com/store/education/certification/authenticate.php?ClientCandidateID=ZEND007769&amp;RegistrationID=225231754" target="_blank">Zend Certified Engineer</a>.</p>
<p><strong>I was 5th ZCE and youngest at that time in</strong> <strong>Bangladesh</strong>, so it impacts a recognizable value in my career, and I got a very good job with better salary in a Bangladeshi Company named <a href="http://www.trippertlabs.com/" target="_blank">Trippert Labs, Inc.</a> I am also grateful to <a href="http://hasin.wordpress.com" target="_blank">Hasin Hayder</a> brother because he made this happen and gave me the opportunity to work with him. In <strong>late 2008</strong> he joined another company named <a href="http://i2we.com" target="_blank">i2we, inc.</a> and in <strong>December 2008</strong> I also joined there by the reference of <a href="http://hasin.wordpress.com" target="_blank">Hasin Hayder </a>brother. And <strong>I worked with Hasin bro</strong> <strong>more than 2 years in </strong><a href="http://i2we.com" target="_blank">i2we, inc. </a>He is highly expert, experienced and real guru of web technology. I learned many things from him. By the way I married my lover in the middle of <strong>2009</strong> <img src='http://c3354688.r88.cf0.rackcdn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Help others to get help from God</h2>
<p><strong>I’m a muslim</strong> and <strong>I believe in Allah</strong> (HE IS God the one the most unique). I started my blog in the beginning of <strong>2009</strong> by the inspire of Hasin brother. My blog become very familiar for facebook related tutorials. Why? Because I work on facebook applications more than 2 years and I share my knowledge with others. So that people can follow my solution to solve their problem. I’m not regular in my writing but I wish to write regularly and now a days I’m not actively working on facebook. But still I try to share my knowledge with others.</p>
<h2>Now what different ?</h2>
<p>From <strong>2009</strong> I was involved <strong>part time freelancing</strong> via my blog and freelance sites. And I’ve a high profile in oDesk. My clients are happy because I’m honest and dedicated to work on their project. <strong>Never think client’s project as different rather think that project is your. Only then you can do best work and your client will become happy.</strong></p>
<p><strong>In late 2010</strong>, one day <strong><a href="http://www.facebook.com/trivuz" target="_blank">Trivuz</a> bro showed me why Mac is better than windows</strong>. I suddenly felt I should use mac and develop iOS applications as I already inspired about iPhone. So I purchased MacBook Pro and iPod Touch and later iPad.</p>
<h2>Objective C</h2>
<p>At first <strong>I became afraid to see this language syntax</strong>. But I was studying and after some weeks I learned that language very well. <strong>Objective C is a beautiful language</strong> based on C. If you’re really a good programmer and know OOP well its a matter of time to expert on this language. By the way &#8220;nothing goes unpaid&#8221;. My j2me applications development experience helped me on iPhone applications development, C++ experience is helping me to work with Box2D physics engine to make 2D game.</p>
<p>I developed several applications using XCode, Objective C and also now I’m fascinated about 2D game development using Objective C based Cocos2D framework. My wife is helping me on the graphics design part of the iOS applications.  You’ll see all of my iOS applications and games from here <a href="http://ithinkdiff.net" target="_blank">iThinkdiff.net</a></p>
<p><strong>3 of my popular iOS applications and 2 game:</strong></p>
<ol>
<li><a href="http://ithinkdiff.net/iphone-applications/bengali-dictionary/" target="_blank">Bengali Dictionary</a></li>
<li><a href="http://ithinkdiff.net/iphone-applications/arabic-dictionary/" target="_blank">Arabic Dictionary</a></li>
<li><a href="http://ithinkdiff.net/reference/translator-free/" target="_blank">Translator Free</a></li>
<li><a href="http://ithinkdiff.net/ios-games/assumption/" target="_blank">Assumption</a> (not so popular, it was my 2nd game)</li>
<li><a href="http://ithinkdiff.net/ios-games/cubilus/" target="_blank">Cubilus</a> (my latest game)</li>
</ol>
<h2>What else?</h2>
<p>I quit my regular job from<a href="http://i2we.com" target="_blank"> i2we, inc</a>. in <strong>December 2010</strong>. I still working as a part time freelancer  and currently working in a  startup web project, I’m the architect and lead developer of that project. Currently my hourly rate is around 23~30 USD per hour for web development. In rest of the time I work on my personal iOS applications. So I haven’t quit my web development job, I’m just making extra time to take different taste of programming on different platforms.</p>
<p>I&#8217;ve a plan to apply for immigrations in Australia, Canada or any well known country in near future. So I&#8217;m looking for job/sponsorship before I apply.</p>
<p>And I like my bike, I’m learning guitar by video tutorials and also I’ve some fascination about photography. I&#8217;m enjoying my life with my family, my friends and you (<strong>my blog readers)</strong>. Thanks for reading my blog posts. You (blog readers) are my friend and you made my blog useful.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/zAAnCsgq4uLBd1QAR9ZkRCbJYwM/0/da"><img src="http://feedads.g.doubleclick.net/~a/zAAnCsgq4uLBd1QAR9ZkRCbJYwM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zAAnCsgq4uLBd1QAR9ZkRCbJYwM/1/da"><img src="http://feedads.g.doubleclick.net/~a/zAAnCsgq4uLBd1QAR9ZkRCbJYwM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/Jz7P06ED0w4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/personal/beginning-of-my-career/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/personal/beginning-of-my-career/</feedburner:origLink></item>
		<item>
		<title>PHP SDK 3.0 &amp; Graph API base Facebook Connect Tutorial</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/SFPz308UsOI/</link>
		<comments>http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/#comments</comments>
		<pubDate>Wed, 25 May 2011 20:50:25 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[facebook php]]></category>
		<category><![CDATA[sdk 3.0]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2279</guid>
		<description><![CDATA[Facebook recently updated their PHP-SDK to version 3.0 also added new way of authentication. This is a major change. So this is the updated post of my old popular post. In this version of my code, I avoided javascript authentication, because that is cookie based and php sdk 3.0 has some conflicts with the old [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" rel="lightbox[2279]"><img class="alignleft size-full wp-image-2142" title="facebook" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" alt="facebook" width="200" height="150" /></a>Facebook recently <a href="http://developers.facebook.com/blog/post/503" target="_blank">updated their PHP-SDK</a> to version <strong>3.0 </strong>also added new way of authentication. This is a major change. So this is the updated post of my <a href="http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/" target="_blank">old popular post</a>.</p>
<p>In this version of my code, I avoided javascript authentication, because that is cookie based and php sdk 3.0 has some conflicts with the old system. Facebook will also update the javascript sdk soon, so later you can use the login/logout system of javascript api with php sdk. But for now you should use fully php base authentication.</p>
<p><strong>In this post you&#8217;ll learn:</strong></p>
<ol>
<li>How to integrate Facebook Connect in your website</li>
<li>How to generate Facebook Login / Logout URL</li>
<li>How to get extended permissions from users</li>
<li>How to call graph api</li>
<li>How to run FQL Query</li>
<li>Publish Wall Post using PHP</li>
<li>Publish Wall Post using Facebook Javascript API</li>
<li>Invite friends using Facebook Javascript API</li>
<li>No Facebook Javascript only use PHP SDK</li>
</ol>
<p><span id="more-2279"></span></p>
<p><strong>Before proceeding:</strong></p>
<p><a href="http://thinkdiff.net/demo/newfbconnect1/php/sdk3/index.php" target="_blank"><img class="alignnone size-full wp-image-2402" title="Demo App" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/demo_application.jpg" alt="Demo App" width="270" height="85" /></a><a href="https://github.com/mahmudahsan/PHP-SDK-3.0---Graph-API-base-Facebook-Connect-Tutorial-Source" target="_blank"><img class="alignnone size-full wp-image-2403" title="Download Code" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/download_code.jpg" alt="" width="270" height="85" /></a></p>
<p><em>For iFrame Base Facebook app <a href="http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development-php-sdk-3-0/" target="_blank">checkout this tutorial</a></em></p>
<h2>1. How to integrate Facebook Connect in your website</h2>
<p style="text-align: center;"><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/files_fbconnect.jpg" rel="lightbox[2279]"><img class="aligncenter size-full wp-image-2280" title="files_fbconnect" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/files_fbconnect.jpg" alt="" width="443" height="203" /></a></p>
<p>You have to create a facebook app and provide callback url. Checkout some screenshots <a href="http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development/" target="_blank">of this article</a>. If you unzip my downloaded code you&#8217;ll see these files (fig) where fbmain.php and index.php is coded by me. Then just copy the appid and secret key and paste them in the <strong>fbmain.php . </strong>I put all authentication and graph api code in fbmain.php and index.php is used for showing them, but remember index.php is the main file that you mention in your callback url . And this file includes fbmain.php at top.</p>
<pre class="brush: php; title: ; notranslate">
//facebook application
    $fbconfig['appid' ]     = &quot;&quot;;
    $fbconfig['secret']     = &quot;&quot;;
    $fbconfig['baseurl']    = &quot;&quot;;// &quot;http://thinkdiff.net/demo/newfbconnect1/php/sdk3/index.php&quot;;
</pre>
<h2>2. How to generate Facebook Login / Logout URL</h2>
<p>In fbmain.php you&#8217;ll see</p>
<pre class="brush: php; title: ; notranslate">
$loginUrl   = $facebook-&gt;getLoginUrl(
            array(
                'scope'         =&gt; 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
                'redirect_uri'  =&gt; $fbconfig['baseurl']
            )
    );

    $logoutUrl  = $facebook-&gt;getLogoutUrl();
</pre>
<p>and in template.php you&#8217;ll see this code. This code shows user the login and logout url.</p>
<pre class="brush: php; title: ; notranslate">
 &lt;?php if (!$user) { ?&gt;
        You've to login using FB Login Button to see api calling result.
        &lt;a href=&quot;&lt;?=$loginUrl?&gt;&quot;&gt;Facebook Login&lt;/a&gt;
    &lt;?php } else { ?&gt;
        &lt;a href=&quot;&lt;?=$logoutUrl?&gt;&quot;&gt;Facebook Logout&lt;/a&gt;
    &lt;?php } ?&gt;
</pre>
<p><strong>To learn about authentication</strong> and <strong>$user</strong> please<a href="http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development-php-sdk-3-0/" target="_blank"> follow this tutorial</a></p>
<h2>3. How to get extended permissions from users</h2>
<p>You&#8217;ve to provide the extended permission at the time when you generate login url. And this is &#8216;scope&#8217; where you&#8217;ll provide the extended permissions as a comma separated list.</p>
<pre class="brush: php; title: ; notranslate">
$loginUrl   = $facebook-&gt;getLoginUrl(
            array(
                'scope'         =&gt; 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
                'redirect_uri'  =&gt; $fbconfig['baseurl']
            )
    );
</pre>
<p>To know more about extended permissions visit <a href="http://developers.facebook.com/docs/authentication/permissions/" target="_blank">facebook official documentation</a></p>
<h2>4. How to call graph api</h2>
<p>Its very simple. You&#8217;ll see below code in fbmain.php</p>
<pre class="brush: php; title: ; notranslate">
       //get user basic description using graph api
        $userInfo           = $facebook-&gt;api(&quot;/$user&quot;);

        //Retriving movies those are user like using graph api
        try{
            $movies = $facebook-&gt;api(&quot;/$user/movies&quot;);
        }
        catch(Exception $o){
            d($o);
        }
</pre>
<p>To know more about graph api visit <a href="http://developers.facebook.com/docs/reference/api/" target="_blank">facebook official documentation</a></p>
<h2>5. How to run FQL Query</h2>
<p>In fbmain.php you&#8217;ll see below code</p>
<pre class="brush: php; title: ; notranslate">
try{
            $fql    =   &quot;select name, hometown_location, sex, pic_square from user where uid=&quot; . $user;
            $param  =   array(
                'method'    =&gt; 'fql.query',
                'query'     =&gt; $fql,
                'callback'  =&gt; ''
            );
            $fqlResult   =   $facebook-&gt;api($param);
        }
        catch(Exception $o){
            d($o);
        }
</pre>
<p>To know more about FQL checkout <a href="http://developers.facebook.com/docs/reference/fql/">facebook official documentation</a></p>
<h2>6. Publish Wall Post using PHP</h2>
<p>In fbmain.php you&#8217;ll see below code, if $_GET['publish'] is set then using php sdk and graph api the post will publish in user&#8217;s profile. You can write this code in separate php file and call via ajax to publish, in my example I use normal way to publish with no ajax. In the demo you&#8217;ll see <strong>Publish Post using PHP</strong> so click this link to publish in your wall.</p>
<pre class="brush: php; title: ; notranslate">
if (isset($_GET['publish'])){
            try {
                $publishStream = $facebook-&gt;api(&quot;/$user/feed&quot;, 'post', array(
                    'message' =&gt; &quot;I love thinkdiff.net for facebook app development tutorials. <img src='http://c3354688.r88.cf0.rackcdn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &quot;,
                    'link'    =&gt; 'http://ithinkdiff.net',
                    'picture' =&gt; 'http://thinkdiff.net/ithinkdiff.png',
                    'name'    =&gt; 'iOS Apps &amp; Games',
                    'description'=&gt; 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'
                    )
                );
                //as $_GET['publish'] is set so remove it by redirecting user to the base url
            } catch (FacebookApiException $e) {
                d($e);
            }
        }
</pre>
<h2>7. Publish Wall Post using Facebook Javascript API</h2>
<p>In index.php you&#8217;ll see a javascript function</p>
<pre class="brush: jscript; title: ; notranslate">
function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
                FB.ui({ method : 'feed',
                        message: userPrompt,
                        link   :  hrefLink,
                        caption:  hrefTitle,
                        picture: 'http://thinkdiff.net/ithinkdiff.png'
               });
               //http://developers.facebook.com/docs/reference/dialogs/feed/

            }
</pre>
<p>If you call this method, you&#8217;ll see a popup windows, that will prompt you to publish in your wall. In this case you don&#8217;t need any php.</p>
<h2>8. Invite friends using Facebook Javascript API</h2>
<p>Same as above in index.php you&#8217;ll see a javascript function. Just call this function to see a Request dialog.</p>
<pre class="brush: jscript; title: ; notranslate">
function newInvite(){
                 var receiverUserIds = FB.ui({
                        method : 'apprequests',
                        message: 'Come on man checkout my applications. visit http://ithinkdiff.net',
                 },
                 function(receiverUserIds) {
                          console.log(&quot;IDS : &quot; + receiverUserIds.request_ids);
                        }
                 );
                 //http://developers.facebook.com/docs/reference/dialogs/requests/
            }
</pre>
<h2>9. No Facebook Javascript only use PHP SDK</h2>
<p>If you don&#8217;t want to use any facebook javascript api, then remove all the javascript code from index.php and also remove below part</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://connect.facebook.net/en_US/all.js&quot;&gt;&lt;/script&gt;
     &lt;script type=&quot;text/javascript&quot;&gt;
       FB.init({
         appId  : '&lt;?=$fbconfig['appid']?&gt;',
         status : true, // check login status
         cookie : true, // enable cookies to allow the server to access the session
         xfbml  : true  // parse XFBML
       });

     &lt;/script&gt;
</pre>
<p>If you <strong>remove the above part facebook javascript will not work</strong>.</p>
<p>Hope this tutorial will help you to understand PHP SDK 3.0 and its usage properly. <em></em></p>

<p><a href="http://feedads.g.doubleclick.net/~a/QISSUubzd0kNTYHY5E4tfHdOV6k/0/da"><img src="http://feedads.g.doubleclick.net/~a/QISSUubzd0kNTYHY5E4tfHdOV6k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/QISSUubzd0kNTYHY5E4tfHdOV6k/1/da"><img src="http://feedads.g.doubleclick.net/~a/QISSUubzd0kNTYHY5E4tfHdOV6k/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/SFPz308UsOI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/feed/</wfw:commentRss>
		<slash:comments>169</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/</feedburner:origLink></item>
		<item>
		<title>Graph API &amp; IFrame Base Facebook Application Development PHP SDK 3.0</title>
		<link>http://feedproxy.google.com/~r/thinkdiff/IhBP/~3/ao-vauDK-mU/</link>
		<comments>http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development-php-sdk-3-0/#comments</comments>
		<pubDate>Sat, 21 May 2011 22:08:37 +0000</pubDate>
		<dc:creator>mahmud ahsan</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[php sdk3.0]]></category>

		<guid isPermaLink="false">http://thinkdiff.net/?p=2259</guid>
		<description><![CDATA[Facebook recently updated their PHP-SDK to version 3.0. This is a major change. So I decided to update some of my facebook related tutorials with updated code. At first I want to tell you that, this post is the updated version of my popular post Graph API &#38; IFrame Base Facebook Application Development . So [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" rel="lightbox[2259]"><img class="alignleft size-full wp-image-2142" title="facebook" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/01/facebook-new.jpg" alt="facebook" width="200" height="150" /></a>Facebook recently <a href="http://developers.facebook.com/blog/post/503" target="_blank">updated their PHP-SDK</a> to version <strong>3.0</strong>. This is a major change. So I decided to update some of my facebook related tutorials with updated code.</p>
<p>At first I want to tell you that, this post is the updated version of my popular post <a href="http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development/" target="_blank">Graph API &amp; IFrame Base Facebook Application Development</a> . So if you never saw that tutorial I request you to visit that and learn the basic things specially facebook application setup. Also on that post I mentioned some important things regarding iframe, so in this post I&#8217;ll not mention them again.</p>
<p><strong>So in this updated post we will learn:</strong></p>
<ol>
<li>How to update facebook php sdk 3.0 library</li>
<li>Authentication</li>
<li>How to give extended permissions</li>
<li>How to call graph api</li>
<li>How to publish stream using facebook&#8217;s latest dialog system</li>
<li>How to request/invite your friends and track them</li>
</ol>
<p><span id="more-2259"></span></p>
<p><strong>Before proceeding:</strong></p>
<p><a href="http://apps.facebook.com/thinkdiffdemo/" target="_blank"><img class="alignnone size-full wp-image-2402" title="Demo App" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/demo_application.jpg" alt="Demo App" width="270" height="85" /></a><a href="https://github.com/mahmudahsan/Graph-API---IFrame-Base-Facebook-Application-Development-PHP-SDK-3.0--Source" target="_blank"><img class="alignnone size-full wp-image-2403" title="Download Code" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/07/download_code.jpg" alt="Download Code" width="270" height="85" /></a></p>
<h2>1. How to update facebook php sdk 3.0 library</h2>
<p>First download <a href="https://github.com/facebook/php-sdk/" target="_blank">Facebook&#8217;s php sdk</a> and from the /src directory copy<strong><em> facebook.php, base_facebook.php and fb_ca_chain_bundle.crt</em></strong> to your project dir. Then download my codes from <a href="https://github.com/mahmudahsan/Graph-API---IFrame-Base-Facebook-Application-Development-PHP-SDK-3.0--Source" target="_blank">here</a>, in this zip file you also get the php sdk libraries. Now click below image to know about the files functionality.</p>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/facebook_phpsdk3.jpg" rel="lightbox[2259]"><img class="aligncenter size-full wp-image-2262" title="facebook_phpsdk3" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/facebook_phpsdk3.jpg" alt="facebook_phpsdk3" width="543" height="90" /></a></p>
<h2>2. Authentication</h2>
<p>In fbmain.php <strong>line number 23-&gt;77</strong> you&#8217;ll see below code.</p>
<ul>
<li>At first we include the <strong>facebook.php</strong> library.</li>
<li>Then we created a $facebook object</li>
<li>Then we check if there is a valid session for user by  $user = $facebook-&gt;getUser();</li>
<li>Then we generate login url with extended permission</li>
<li>At <strong>line number 62</strong> we call graph api $user_profile = $facebook-&gt;api(&#8216;/me&#8217;);    to check if session is valid or not. If we get result then user&#8217;s session is valid otherwise we set $user = null that means expired or timeout session.</li>
<li>If no valid $user found at <strong>line number 71</strong> we redirect user to login/authentication page for our application.</li>
</ul>
<pre class="brush: php; title: ; notranslate">
$user            =   null; //facebook user uid
    try{
        include_once &quot;facebook.php&quot;;
    }
    catch(Exception $o){
        echo '&lt;pre&gt;';
        print_r($o);
        echo '&lt;/pre&gt;';
    }
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  =&gt; $fbconfig['appid'],
      'secret' =&gt; $fbconfig['secret'],
      'cookie' =&gt; true,
    ));

    //Facebook Authentication part
    $user       = $facebook-&gt;getUser();
    $loginUrl   = $facebook-&gt;getLoginUrl(
            array(
                'scope'         =&gt; 'email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown'
            )
    );

    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook-&gt;api('/me');
      } catch (FacebookApiException $e) {
        //you should use error_log($e); instead of printing the info on browser
        d($e);  // d is a debug function defined at the end of this file
        $user = null;
      }
    }

    if (!$user) {
        echo &quot;&lt;script type='text/javascript'&gt;top.location.href = '$loginUrl';&lt;/script&gt;&quot;;
        exit;
    }
</pre>
<p>After user successfully authenticated our application facebook will redirect user to our <strong>callback url</strong> that we provided in the developer application setting. Facebook additionally pass a parameter named <strong>code=XXXX . </strong>But as this is a iframe application that runs inside facebook so we used a special code at <strong>line number 16-&gt;19</strong>. This code checks if there is GET parameter code is defined or not, if its defined then it redirects user to the facebook app url.</p>
<pre class="brush: php; title: ; notranslate">
if (isset($_GET['code'])){
        header(&quot;Location: &quot; . $fbconfig['appBaseUrl']);
        exit;
    }
</pre>
<h2>3. How to give extended permissions</h2>
<p>When you&#8217;ll generate the login url you&#8217;ve to provide extended permissions here. Previously the parameter named was <em>‘req_perms&#8217; and now its &#8216;scope&#8217;.<br />
</em></p>
<pre class="brush: php; title: ; notranslate">
 $loginUrl   = $facebook-&gt;getLoginUrl(
            array(
                'scope'         =&gt; 'email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown'
            )
    );
</pre>
<p>Checkout <a href="http://developers.facebook.com/docs/authentication/permissions" target="_blank">extended permission list from here</a>.</p>
<h2>4. How to call graph api</h2>
<p>In fbmain.php <strong>line number 76</strong>, you&#8217;ll see how I called the graph api. Here $user is facebook user&#8217;s UID. To know more about <a href="http://developers.facebook.com/docs/reference/api/" target="_blank">graph api visit this page</a></p>
<pre class="brush: php; title: ; notranslate">
//get user basic description
    $userInfo           = $facebook-&gt;api(&quot;/$user&quot;);
</pre>
<h2>5. How to publish stream using facebook&#8217;s latest dialog system</h2>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/stream_box.jpg" rel="lightbox[2259]"><img class="aligncenter size-full wp-image-2263" title="stream_box" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/stream_box.jpg" alt="" width="534" height="283" /></a></p>
<p>In template.php <strong>line number 50-&gt;54</strong> you&#8217;ll see the facebook&#8217;s javascript function. To know more about <a href="http://developers.facebook.com/docs/reference/dialogs/feed/" target="_blank">feed please visit here.</a></p>
<pre class="brush: jscript; title: ; notranslate">
FB.ui({ method : 'feed',
                        message: userPrompt,
                        link   :  hrefLink,
                        caption:  hrefTitle
                      });
</pre>
<h2>6. How to request/invite your friends and track them</h2>
<p><a href="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/request_page.jpg" rel="lightbox[2259]"><img class="aligncenter size-full wp-image-2269" title="request_page" src="http://c3354688.r88.cf0.rackcdn.com/wp-content/uploads/2011/05/request_page.jpg" alt="" width="535" height="465" /></a></p>
<p>So you want your user will invite his friends to use this application, and also you want to track to whom your user sends request. Also you want to check if that user is come from via request or not. In <a href="http://apps.facebook.com/thinkdiffdemo/" target="_blank">demo application</a> click <strong>Send Request/Send Invitation</strong> to check the request dialog. In template.php <strong>line number 88</strong> you&#8217;ll see this function.</p>
<pre class="brush: jscript; title: ; notranslate">
function newInvite(){
                 var receiverUserIds = FB.ui({
                        method : 'apprequests',
                        message: 'come on man checkout my application. visit http://thinkdiff.net',
                 },
                 function(receiverUserIds) {
                          console.log(&quot;IDS : &quot; + receiverUserIds.request_ids);
                        }
                 );
                 //http://developers.facebook.com/docs/reference/dialogs/requests/
            }
</pre>
<p>This function show a invite dialog and if user selects friends and sends invite, then in the response you&#8217;ll get all of user&#8217;s friends UIDs as a comma separated string. So if you use <strong>Firebug in Firefox</strong>, you&#8217;ll see <strong>console.log(&#8220;IDS : &#8221; + receiverUserIds.request_ids); will print IDS: XXXX in the console of firebug</strong>. So if you want to track the friends IDS who received invitation, then parse <strong>receiverUserIds</strong> and save them in your mysql database.</p>
<p>If a user authenticate your application from invitation then his URL would be</p>
<pre>http://apps.facebook.com/[app_name]/?request_ids=012345678910</pre>
<p>So in fbmain.php <strong>line number 23-&gt;26</strong> you&#8217;ll see below code. I just blank them you&#8217;ve to write additional code for tracking user.</p>
<pre class="brush: php; title: ; notranslate">
if (isset($_GET['request_ids'])){
        //user comes from invitation
        //track them if you need
    }
</pre>
<p>I hope this tutorial will help you for developing facebook application.</p>
<p style="text-align: center;"> <img src='http://c3354688.r88.cf0.rackcdn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p><a href="http://feedads.g.doubleclick.net/~a/RiTunJAvuk3OBSPwtKjnZjpZuvY/0/da"><img src="http://feedads.g.doubleclick.net/~a/RiTunJAvuk3OBSPwtKjnZjpZuvY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/RiTunJAvuk3OBSPwtKjnZjpZuvY/1/da"><img src="http://feedads.g.doubleclick.net/~a/RiTunJAvuk3OBSPwtKjnZjpZuvY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/thinkdiff/IhBP/~4/ao-vauDK-mU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development-php-sdk-3-0/feed/</wfw:commentRss>
		<slash:comments>197</slash:comments>
		<feedburner:origLink>http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development-php-sdk-3-0/</feedburner:origLink></item>
	</channel>
</rss><!-- Served from: games.thinkdiff.net @ 2012-01-26 13:49:41 by W3 Total Cache -->

