<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>25 labs</title>
	<atom:link href="http://25labs.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://25labs.com</link>
	<description>25 labs is a Technology blog that covers the tech stuffs happening around the globe. 25 labs publishes various tutorials and articles on web designing, Facebook API, Google API etc.</description>
	<lastBuildDate>Sun, 21 Apr 2013 06:30:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<atom:link rel='hub' href='http://25labs.com/?pushpress=hub'/>
		<item>
		<title>Tutorial: Post to multiple Facebook wall or timeline in one go using Graph API batch request</title>
		<link>http://25labs.com/tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request</link>
		<comments>http://25labs.com/tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 20:43:09 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=186</guid>
		<description><![CDATA[<p><img width="400" height="400" src="http://25labs.com/wp-content/uploads/2012/03/facebook-developer-timeline-post.jpg" class="attachment-medium wp-post-image" alt="Facebook developer Timeline Post" /></p>Many Facebook application developers might have come across a situation where they need to post something to many pages, groups or friends. If we need to post on 50 walls and go by the traditional method of posting one by one, we would need 50 requests to Graph API. Each request will take its time [...]]]></description>
				<content:encoded><![CDATA[<p><img width="400" height="400" src="http://25labs.com/wp-content/uploads/2012/03/facebook-developer-timeline-post.jpg" class="attachment-medium wp-post-image" alt="Facebook developer Timeline Post" /></p><p>Many Facebook application developers might have come across a situation where they need to post something to many pages, groups or friends. If we need to post on 50 walls and go by the traditional method of posting one by one, we would need 50 requests to Graph API. Each request will take its time and the webpage will take ages to load. In such situation Batch Request of Graph API comes to our rescue. All types of request to Graph API (GET, POST, DELETE etc) can be clubbed together to form a batch request. So we can post a status, delete a comment, like a post or whatever you wish, just by sending one request to Facebook. In this tutorial we will be using Facebook PHP SDK for the implementation. We will create a webpage that lists all your friends, groups and pages that you liked. You can post custom messages, pictures or links to selected walls or groups.</p>
<p>If you are looking for a basic tutorial on Facebook connect or wish to know the basics of Graph API, please head to: <a title="Tutorial: Integrate Facebook Connect to your website using PHP SDK v.3.x.x which uses Graph API" href="http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/" target="_blank">Tutorial: Integrate Facebook Connect to your website using PHP SDK</a></p>
<p style="margin-top: 10px; margin-left: 0; background: #FFD9C8; border: 1px solid #F37C72; padding: 20px; overflow: hidden;"><strong>NOTE: </strong>Even though you will be able to post to Pages and Groups, this app will <strong>NOT</strong> be able to post to friend&#8217;s wall as Facebook has deprecated post to friend&#8217;s wall via API, and the reason they state is:<br />
Post to friends wall via the API generate a high levels of negative user feedback, including “Hides” and “Mark as Spam&#8221; and so we are removing it from the API. If you want to allow people to post to their friend’s timeline from your app, you can invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag).<br />
Refer <a href="https://developers.facebook.com/blog/post/2012/10/10/growing-quality-apps-with-open-graph/" target="_blank">Facebook blog</a> for details.</p>
<p><center><a href="http://25labs.com/demo/post-to-multiple-facebook-wall/" target="_blank"><img style="margin-right: 10px;" alt="" src="http://25labs.com/images/view-demo.png" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px;" alt="" src="http://25labs.com/images/download-source.png" /></a></center></p>
<h3>Step 1 to 4 : Registering your application and Downloading PHP SDK</h3>
<p>The primary thing to do is to register your facebook application and obtain an App ID and App secret. Then you will need to download the PHP SDK from Facebook Developer website. If you are a newbie or not sure how to do it, please refer the article <a title="Tutorial: Integrate Facebook Connect to your website using PHP SDK v.3.x.x which uses Graph API" href="http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/" target="_blank">Tutorial: Integrate Facebook Connect to your website using PHP SDK</a> and follow Step 1 to 4.</p>
<h2>Creating the access file (fbaccess.php)</h2>
<p>Now we will create a file named &#8216;fbaccess.php&#8217; which will be the heart of our web application. All the Facebook API calls and requests will be in this file.</p>
<h3>Step 5 to 7 : Application Configuration, Creating app instance and User authentication</h3>
<p>Please follow Step 5 to 7 form the article <a title="Tutorial: Integrate Facebook Connect to your website using PHP SDK v.3.x.x which uses Graph API" href="http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/" target="_blank">Tutorial: Integrate Facebook Connect to your website using PHP SDK</a>.</p>
<p>The above steps will give you a code similar to:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Application Configurations</span>
<span style="color: #000088;">$app_id</span>        <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your App ID goes here&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$app_secret</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your App Secret goes here&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$site_url</span>      <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your Site URL goes here&quot;</span><span style="color: #339933;">;</span>
&nbsp;
try<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;src/facebook.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Create our application instance</span>
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'appId'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$app_id</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'secret'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$app_secret</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get User ID</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    try<span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Proceed knowing you have a logged in user who's authenticated.</span>
        <span style="color: #000088;">$user_profile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Step 8:</h3>
<p>Variable $user will have the user ID if we have an authenticated user. In that case, we will need to create the logout URL. If we have a user who is not authenticated, then we need to generate the login URL. We use the function getLoginUrl() and getLogoutUrl() to generate login and logout URL respectively. In our demo we will need to include only &#8216;publish_stream&#8217; and &#8216;user_groups&#8217; as scope parameters. With &#8216;publish_stream&#8217; permission we can publish a post to your friend&#8217;s timeline or to a page that you liked. &#8216;user_groups&#8217; permission grants information about the Facebook groups in which the application user is a member.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Get logout URL</span>
    <span style="color: #000088;">$logoutUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogoutUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Get login URL</span>
    <span style="color: #000088;">$loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'scope'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'publish_stream user_groups'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'redirect_uri'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$site_url</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Step 9:</h3>
<p>In this step we will retrieve the logged in user’s details, his friend list, his groups and also the pages that he liked. We will retrieve these 4 items with just one request to Facebook Graph API using batch request. If we were to go by the normal method of not using the batch API we will need 4 requests to Graph API. With 4 requests the details can be retrieved as shown below.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user_info</span>         <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$friends_list</span>      <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$groups</span>            <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/groups'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pages</span>             <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/likes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Using batch request will cut down the requests from 4 to 1. For a batch request first step is to save the method calls into an array. We make an array named $queries and push each of the 4 requests into it.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$queries</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/groups'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/likes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then we will POST the array as a single request as shown below.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">try<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$batchResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?batch='</span><span style="color: #339933;">.</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$o</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$o</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The request will return the values that we requested indexed in the order of the array as a JSON. We will get the required user info, friends list, groups and pages by decoding the JSON.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user_info</span>         <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$friends_list</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$groups</span>            <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pages</span>             <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Step 10:</h3>
<p>Now we can write the code for the batch posting. Here we assume that the content to be posted and the IDs of friends, groups and pages where the matter need to be posted is available in the $_POST variable. $_POST variable is a collection of key =&gt; value pairs and we assume that each IDs in the variable has a ‘id_’ prefix in the key. Thus by checking for the prefix ‘id_’ we can identify the User IDs, Groups IDs and Page IDs where the content is to be posted.</p>
<p>The basic method is same as in Step 9. First we need to make an array and push each and every Graph API request to the array. Then we will post the array as a single request to graph API using the function api().</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/{ID1}/feed&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/{ID2}/feed&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/{ID3}/feed&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$multiPostResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?batch='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Here $body is an array which has many key =&gt; value pairs. We use the function http_build_query() to URL encode the array. http_build_query() generates a URL-encoded query string from the associative (or indexed) array provided.</p>
<p>json_encode() returns a string containing the JSON representation of the array. We need to pass this string to the api() function for the batch request. As we made the string from multi-dimensional arrays there may be some issues like posting blank messages to user’s wall or timeline. The API request is similar to a URL query. So we need to encode the string to match the format. urlencode() is used for encoding a string to be used in a query part of a URL. This will solve the issue of posting blank data to the timeline.</p>
<p>Now we will modify the code to suit our application. First we will generate the array $body. We will get the data to be posted to user’s timeline from the $_POST variable. In this particular demo we will use just 6 of many possible post fields. The 6 fields that we use are message, link, picture, name, caption, and description. If you wish to have more fields please refer <a title="Facebook Documentaion on Post" href="http://developers.facebook.com/docs/reference/api/post/" target="_blank">Facebook documentation</a> for information on all possible fields.</p>
<p>A picture is worth a thousand words. So please see the images below to know what the fields are. The first pic shows the legacy Facebook wall and the second one shows how the post will look in the timeline. Of the 6 fields that we use 5 are shown there. The sixth one is ‘link’ field. In the ‘link’ field we specify the hyperlink for the ‘name’ field.</p>
<div id="attachment_488" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2012/03/sample-post.jpg"><img class="size-medium wp-image-488" title="Sample Post" alt="Sample post with details" src="http://25labs.com/wp-content/uploads/2012/03/sample-post-420x164.jpg" width="420" height="164" /></a><p class="wp-caption-text">Sample Wall post with field details</p></div>
<div id="attachment_501" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2012/03/sample-post-timeline.jpg"><img class="size-medium wp-image-501" title="sample-post-timeline" alt="Sample Post Timeline" src="http://25labs.com/wp-content/uploads/2012/03/sample-post-timeline-420x261.jpg" width="420" height="261" /></a><p class="wp-caption-text">Sample Timeline post with field details</p></div>
<p>Now we need to generate Graph API request for each and push them to an array. Each request will need the ID of the user, group or page. For each key =&gt; value pair in the $_POST variable, we check for the prefix ‘id_’ in the key and if found we can confirm that the value associated with the key is an ID. For each IDs we generate Graph API request and push it to $batchPost array.</p>
<p>Another important point to note is that Facebook currently limits the number of batch request to 50. So you can do a maximum of 50 requests at once. So if you have more than 50 requests then you will have to do multiple batch requests. In our application, once the $batchPost array accumulates 50 requests we do a batch request and then flushes the array.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'message'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'link'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'picture'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'picture'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'name'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'caption'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'caption'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'description'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$batchPost</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;id_&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$value</span>/feed&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'body'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                try<span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$multiPostResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'?batch='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'POST'</span>
                        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Batch Post Failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        try<span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$multiPostResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?batch='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchPost</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Batch Post Failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>‘fbaccess.php’ is now complete and we will proceed to ‘index.php’.</p>
<h2>Creating the main webpage (index.php)</h2>
<h3>Step 11:</h3>
<p>In ‘index.php’, the first thing to do is to check whether the user is authenticated or not. If we have a user who is not authenticated, display a login button with the login URL. If we have a login user, we will display a form which has provision for entering custom data to be posted. It will also have option to select the users, groups and pages where the user wishes to post the data.</p>
<p><a href="http://25labs.com/wp-content/uploads/2012/03/form-with-input-text-fields.jpg"><img class="aligncenter size-medium wp-image-504" title="form-with-input-text-fields" alt="form with input text fields" src="http://25labs.com/wp-content/uploads/2012/03/form-with-input-text-fields-420x204.jpg" width="420" height="204" /></a></p>
<p>Create 6 input text fields with names &#8211; message, link, picture, name, caption, and description. Then display the names of friends, pages and groups from the arrays $friends_list, $pages and $groups respectively and associate a check box with each of them. Name the check boxes with prefix ‘id_’ and ID of the object (user, page or group) as the value for the check box. And now add a submit button with name ‘submit’. In this demo script I have used an &#8220;image&#8221; input type to submit the form. For the PHP processing script to work we need to add a &#8220;_x&#8221; suffix to the field name in the processing PHP code, if we use an &#8220;image&#8221; input type to submit the form.</p>
<p>In the demo, I have added few extra functionalities like select all, error messages etc. I have also added a variable $limit which limits the number of displayed entries in each category, that is, friends, pages and groups. I have limited the number to 500 in the demo. You can just change the value of $limit and specify the limit for your code. You can download the complete source of the demo from <a title="Download Source" href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank">here</a>. Please feel free to comment if you find any mistakes or improvements to the script.</p>
<p style="margin-top: 10px; margin-left: 0; background: #FFD9C8; border: 1px solid #F37C72; padding: 20px; overflow: hidden;"><strong>NOTE: </strong>Even though you will be able to post to Pages and Groups, this app will <strong>NOT</strong> be able to post to friend&#8217;s wall as Facebook has deprecated post to friend&#8217;s wall via API, and the reason they state is:<br />
Post to friends wall via the API generate a high levels of negative user feedback, including “Hides” and “Mark as Spam&#8221; and so we are removing it from the API. If you want to allow people to post to their friend’s timeline from your app, you can invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag).<br />
Refer <a href="https://developers.facebook.com/blog/post/2012/10/10/growing-quality-apps-with-open-graph/" target="_blank">Facebook blog</a> for details.</p>
<p><center><a href="http://25labs.com/demo/post-to-multiple-facebook-wall/" target="_blank"><img style="margin-right: 10px;" alt="" src="http://25labs.com/images/view-demo.png" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px;" alt="" src="http://25labs.com/images/download-source.png" /></a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request/feed/</wfw:commentRss>
		<slash:comments>176</slash:comments>
		</item>
		<item>
		<title>Tutorial: Implementing Google+ API using OAuth 2.0 in PHP</title>
		<link>http://25labs.com/tutorial-implementing-google-api-using-oauth-2-0-in-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-implementing-google-api-using-oauth-2-0-in-php</link>
		<comments>http://25labs.com/tutorial-implementing-google-api-using-oauth-2-0-in-php/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 06:30:24 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Web Designing]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google plus]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web designing]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=149</guid>
		<description><![CDATA[<p><img width="256" height="256" src="http://25labs.com/wp-content/uploads/2011/11/google-plus-api.jpg" class="attachment-medium wp-post-image" alt="Google+ API" /></p>On September 15, 2011 Google released Google+ APIs to public. Google+ API is a programming interface to Google+. With the help of this API users can integrate apps or websites with Google+. Currently, Google+ API is in the initial stages of its development. It is not yet a full-fledged API that can support almost anything [...]]]></description>
				<content:encoded><![CDATA[<p><img width="256" height="256" src="http://25labs.com/wp-content/uploads/2011/11/google-plus-api.jpg" class="attachment-medium wp-post-image" alt="Google+ API" /></p><p>On September 15, 2011 Google released Google+ APIs to public. Google+ API is a programming interface to Google+. With the help of this API users can integrate apps or websites with Google+. Currently, Google+ API is in the initial stages of its development. It is not yet a full-fledged API that can support almost anything like Facebook API. Even Google+ itself is not full-fledged Social Network like its rival Facebook. Google engineers are adding more and more features to it, day by day. Recently Google+ Pages was launched which helps to build relationships with your users, encouraging them to spend more time engaging with your content. 25 labs have set up a Google+ Page for itself. You can check it out at <a title="25 labs Google+ page" href="https://plus.google.com/100978449713779879158/" target="_blank">https://plus.google.com/100978449713779879158/</a>. Many such features that are on Facebook are being implemented into Google+. The access provided by Google+ API is currently limited. As of now, Google+ API provides only read-only access to public data. All API calls require either an OAuth 2.0 token or an API key.</p>
<p>This tutorial will give you the basic idea of implementing Google+ API. Google has released many Client Libraries for easy implementation of the API. In this tutorial we will be using Google APIs Client Library for PHP which is currently in beta.</p>
<p><center><a href="http://25labs.com/demo/googleplus/" target="_blank"><img style="margin-right: 10px;" src="http://25labs.com/images/view-demo.png" alt="" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px;" src="http://25labs.com/images/download-source.png" alt="" /></a></center>&nbsp;</p>
<h2>Registering your application</h2>
<p><a href="http://25labs.com/wp-content/uploads/2011/11/google-plus-api.jpg"><img class="alignright size-thumbnail wp-image-150" title="Google+ API" src="http://25labs.com/wp-content/uploads/2011/11/google-plus-api-151x151.jpg" alt="Google+ API" width="151" height="151" /></a>Steps 1 to 7 will explain the procedure of registering the application at Google. You need to register and obtain Client ID, Client secret, Redirect URIs and API key for the application to work.</p>
<h3>Step 1:</h3>
<p>You need to register your product at Google to use Google+ API. To start the registration process, head to <a title="Google API Console" href="http://code.google.com/apis/console" target="_blank">Google API Console</a>.<br />
Create a new project by clicking ‘Create…’ which will be located under the drop down menu that is located at the top left corner of the page, if you have created a project earlier. If you entirely new to Google API console, then ‘Create project…’ button will be right in the middle of the page.</p>
<div id="attachment_416" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/api-projects-drop-down.jpg"><img class="size-medium wp-image-416" title="Project drop down menu" src="http://25labs.com/wp-content/uploads/2011/11/api-projects-drop-down-420x284.jpg" alt="Project drop down menu" width="420" height="284" /></a><p class="wp-caption-text">Project drop down menu</p></div>
<div id="attachment_415" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/api-drop-down-create.jpg"><img class="size-medium wp-image-415 " title="Create in the drop down menu" src="http://25labs.com/wp-content/uploads/2011/11/api-drop-down-create-420x284.jpg" alt="Create in the drop down menu" width="420" height="284" /></a><p class="wp-caption-text">Create in the drop down menu</p></div>
<h3>Step 2:</h3>
<p>You will be taken to the ‘Services’ tab. If not navigate to ‘Services’ tab.</p>
<p>Toggle the Status button next to ‘Google+ API’ to ‘ON’</p>
<div id="attachment_418" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/services-tab.jpg"><img class="size-medium wp-image-418" title="Services tab" src="http://25labs.com/wp-content/uploads/2011/11/services-tab-420x305.jpg" alt="Services tab" width="420" height="305" /></a><p class="wp-caption-text">Services tab</p></div>
<div id="attachment_417" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/google-plus-api-toggle-button.jpg"><img class="size-medium wp-image-417" title="Google+ API toggle button" src="http://25labs.com/wp-content/uploads/2011/11/google-plus-api-toggle-button-420x305.jpg" alt="Google+ API toggle button" width="420" height="305" /></a><p class="wp-caption-text">Google+ API toggle button</p></div>
<h3>Step 3:</h3>
<p>Click ‘API Access’ from the left menu.</p>
<div id="attachment_420" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/api-access.jpg"><img class="size-medium wp-image-420" title="API access" src="http://25labs.com/wp-content/uploads/2011/11/api-access-420x279.jpg" alt="API access" width="420" height="279" /></a><p class="wp-caption-text">API access</p></div>
<h3>Step 4:</h3>
<p>In the page that opens up, click on the ‘Create an OAuth 2.0 client ID…’ button.</p>
<div id="attachment_421" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/create-oauth-client-id.jpg"><img class="size-medium wp-image-421" title="Create OAuth client ID" src="http://25labs.com/wp-content/uploads/2011/11/create-oauth-client-id-420x177.jpg" alt="Create OAuth client ID" width="420" height="177" /></a><p class="wp-caption-text">Create OAuth client ID</p></div>
<h3>Step 5:</h3>
<p>Fill in a name for the project. You can optional give a product logo. The maximum allowed size for the logo is 120 x 60 pixels. This logo will also be displayed on the user’s confirmation page.</p>
<div id="attachment_422" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/enter-client-details.jpg"><img class="size-medium wp-image-422" title="Enter the details" src="http://25labs.com/wp-content/uploads/2011/11/enter-client-details-420x312.jpg" alt="Enter the details" width="420" height="312" /></a><p class="wp-caption-text">Enter the details</p></div>
<p>After you fill in the details click ‘Next’ button.</p>
<h3>Step 6:</h3>
<p>Now you will be taken to Client ID settings page.</p>
<p>Choose ‘Web application’ radio button for the Application type.</p>
<p>In ‘Your site or hostname’ section, choose ‘http://’ or ‘https://’ as per your requirement. Please note that some servers do not support secure protocol (https://) by default. You may need to acquire an SSL certificate to enable https on your server. Authoritatively signed certificates may be free or cost between US$13 and $1,500 per year. So, if you are comfortable with http, then feel free to proceed with it.</p>
<p>Now, enter your domain for the web application. You can also provide ‘localhost’. If you are trying it on localhost, then there is chance that you get a SSL certificate error when the user grants permission to access his details. I have given a possible solution to this problem at the end of this tutorial.</p>
<div id="attachment_424" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/client-id-settings-hostname.jpg"><img class="size-medium wp-image-424" title="Client ID settings hostname" src="http://25labs.com/wp-content/uploads/2011/11/client-id-settings-hostname-420x331.jpg" alt="Client ID settings hostname" width="420" height="331" /></a><p class="wp-caption-text">Client ID settings hostname</p></div>
<p>Now, click ‘more options’ which lies next to ‘Your site or hostname’. Enter the URL that you wish your user to get redirected to, after logging in as the ‘Authorized Redirect URIs’. In my case it is ‘http://localhost/googleplus’. You will automatically have your host address as ‘Authorized JavaScript Origins’.</p>
<div id="attachment_423" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/client-is-settings-redirect-uris.jpg"><img class="size-medium wp-image-423" title="Client ID settings Redirect URIs" src="http://25labs.com/wp-content/uploads/2011/11/client-is-settings-redirect-uris-420x389.jpg" alt="Client ID settings Redirect URIs" width="420" height="389" /></a><p class="wp-caption-text">Client ID settings Redirect URIs</p></div>
<p>Click ‘Create client ID’ button.</p>
<h3>Step 7:</h3>
<p>If everything had gone well, you can view the API credentials for your web application.</p>
<p>Note down the Client ID, Client secret and Redirect URIs which will be under ‘Client ID for web applications’ section. Also note ‘API key’ which comes under the section ‘Simple API Access’. You will need them in Step 9.</p>
<div id="attachment_425" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/11/api-credentials.jpg"><img class="size-medium wp-image-425" title="API credentials" src="http://25labs.com/wp-content/uploads/2011/11/api-credentials-420x389.jpg" alt="API credentials" width="420" height="389" /></a><p class="wp-caption-text">API Credentials</p></div>
<h3>Step 8: (Downloading Client Library)</h3>
<p>Download Google APIs Client Library for PHP. Head to <a href="http://code.google.com/p/google-api-php-client/downloads/list" target="_blank">http://code.google.com/p/google-api-php-client/downloads/list</a> and download the latest version of the Client Library. Extract the compressed file. Inside you will find a folder named ‘google-api-php-client’. Copy the folder to the place where you wish to host the webpage. In my case it is ‘localhost/googleplus’. Please note that this is the ‘Authorized Redirect URIs’ that you provided in Step 6.</p>
<p>At the time of writing this tutorial, the client library version available for download is 0.4.6<br />
I am not sure whether the script will work for future versions. If you find the script broken, please feel free to comment on the post so that I can try and fix the script.</p>
<h3>Step 9: (Creating the access file)</h3>
<p>Now we will start the coding for the implementation of Google+ API. Create a file ‘google-plus-access.php’ in the same place where you copied the folder ‘google-api-php-client’ in the previous step. I will divide the script into various sections and explain each of them.</p>
<p>First we need to include the required files from the API Client that we downloaded in the previous step.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'google-api-php-client/src/apiClient.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'google-api-php-client/src/contrib/apiPlusService.php'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>When a user authenticates, an access token will be returned with which we retrieve the details. We store this access token as a session variable. So we start a session.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then we need to initialize the API client object. Also set a name for the application.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> apiClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setApplicationName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Google+ PHP Starter Application&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now we need to set the API credentials. Replace the arguments with those you created in Step 7.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setClientId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Your Client ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setClientSecret</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Your Client Secret'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirectUri</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Your Redirect URI'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDeveloperKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Your API key'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We use setScopes() function to tell Google what we want to access from the user. In our case we need to access Google+ data. So we provide scope specific to Google+ as argument. You can optionally include scopes for more Google services if you wish.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setScopes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://www.googleapis.com/auth/plus.me'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Initialize the plus API service which takes the API client object as argument.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$plus</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> apiPlusService<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Before getting into the authentication part we need to check whether the user has requested to clear the login information. That is, check whether the user reached the page by clicking the logout button.</p>
<p>We pass a ‘logout’ parameter to the URL to indicate that the user has directed to logout. So we check for ‘logout’ parameter in local URL. If the ‘logout’ parameter is found then we clear the access token from the session.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now we check whether the user clicked allow when the permission for accessing the data was asked for. If the user clicked allow, then there will be ‘code’ parameter in the URL. We check for it and if found, we need to authenticate the user and also store the access token returned by Google in session. We use functions authenticate() and getAccessToken() respectively to achieve them. Then we need to reload the page, but without the code parameter in the URL.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'code'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: http://'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We check whether access token is set in the session. If yes, we can conclude that we have valid access token and so we can pass it to the client.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>getAccessToken() method will return the access token if a valid access token is set to the client and otherwise it will return FALSE. If getAccessToken() returns FALSE, then we need to create the login URL with which the user can login. We use createAuthUrl() method for it.</p>
<p>If an access token is returned, it means that the user is logged in and so we can retrieve the details of the user. We use methods people-&gt;get() and activities-&gt;listActivities() to request for people details and activity details respectively. The only argument for people-&gt;get() is ‘userID’. We pass special value ‘me’ to indicate authenticated user. activities-&gt;listActivities() has two required parameters, ‘userID’ and ‘collection’. Collection specifies the collection of activities to list. Currently ‘public’ is the only acceptable value. We pass an optional parameter to the listActivities() method to set the maximum number of results to be returned. The acceptable values are 1 to 100 and the default value is 20. Then we use the method getAccessToken() to retrieve the access token and update the access token that is stored in session. This is done because the access token may have been updated lazily.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$me</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$plus</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">people</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$optParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'maxResults'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$activities</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$plus</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activities</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">listActivities</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'me'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'public'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$optParams</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$authUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAuthUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This is the end of ’google-plus-access.php’. We will have the variables $me and $activities set once a user is authenticated. We will use these variables to display the data in ‘index.php’ that we are about to create in next step. We will also use variable $authUrl that has the login URL.</p>
<h3>Step 10: (Creating the index file)</h3>
<p>Create ‘index.php’ in same location where you created ’google-plus-access.php’. We must include the file ’google-plus-access.php’ to ‘index.php’.</p>
<p>To find out whether the user is logged in we check whether both $me and $activities are set. If not, we display the login button with the login URL.</p>
<p>$me and $activities are arrays and you can check which all fields are needed for your application by printing them. I have used only few of the available fields for this demo. A point to note is that you can get the profile picture of a user in custom sizes just by appending a GET parameter ‘sz’ which stands for size.</p>
<p>Example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$me</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>?sz=200&quot; /&gt;</pre></td></tr></table></div>

<p><strong>UPDATE:</strong> On 15th November 2011, Google has made a minor change because of which the above line of code will fail to render the image. Earlier $me['image']['url'] used to return the URL to the profile picture at full resolution. But now, by default it returns a thumbnail (of size 50pixel). That is, a GET parameter ‘sz’ with value 50 is appended to URL. So inorder to get the URL to the picture at full resolution we need to strip off the ‘sz’ parameter. So the above code need to be rewritten as:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$me</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">stripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$me</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'?sz='</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>?sz=200&quot; /&gt;</pre></td></tr></table></div>

<p>With this the coding is complete and you can try it out. You can download the complete source of the demo from <a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank">here</a>.</p>
<h3>User Authentication</h3>
<p>When a user clicks the login URL he will be taken to a permission screen similar to the one shown below. If the user clicks ‘allow access’ he will be redirected to your webpage as an authenticated user.</p>
<div id="attachment_426" class="wp-caption aligncenter" style="width: 424px"><a href="http://25labs.com/wp-content/uploads/2011/11/user-authentication.jpg"><img class="size-full wp-image-426" title="User Authentication" src="http://25labs.com/wp-content/uploads/2011/11/user-authentication.jpg" alt="User Authentication" width="414" height="251" /></a><p class="wp-caption-text">User Authentication</p></div>
<h2>Issue you may face</h2>
<p>If you are using localhost on windows to try this code, you may get an SSL certificate error. Once the user grants permission you may see something similar to:</p>
<p>Fatal error: Uncaught exception &#8216;apiIOException&#8217; with message &#8216;HTTP Error: (0) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed&#8217; in C:\xampp\htdocs\googleplus\google-api-php-client\src\io\apiCurlIO.php:127 Stack trace: #0 C:\xampp\htdocs\googleplus\google-api-php-client\src\auth\apiOAuth2.php(87): apiCurlIO-&gt;makeRequest(Object(apiHttpRequest)) #1 C:\xampp\htdocs\googleplus\google-api-php-client\src\apiClient.php(132): apiOAuth2-&gt;authenticate(Array) #2 C:\xampp\htdocs\googleplus\google-plus-access.php(24): apiClient-&gt;authenticate() #3 C:\xampp\htdocs\googleplus\index.php(2): include_once(&#8216;C:\xampp\htdocs&#8230;&#8217;) #4 {main} thrown in C:\xampp\htdocs\googleplus\google-api-php-client\src\io\apiCurlIO.php on line 127</p>
<p>This means that the server is unable to perform peer SSL certificate verification. The Windows version of PHP doesn&#8217;t come bundled with a Certificate Authority bundle. So you need to add it yourself.</p>
<h3>Solution 1:</h3>
<p>In &#8216;google-api-php-client\src\io\&#8217; folder, open &#8216;apiCurlIO.php&#8217;</p>
<p>Replace</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span style="color: #000000;"><strong>UPDATE : </strong></span>As on Jan 17, 2012 the latest version of Google API PHP Client is 0.4.8.3 (Beta) and it has an array $DEFAULT_CURL_PARAMS which sets all the parameters for CURL. And so you won&#8217;t be able to see the above mentioned line of code. I have update the demo source bundle with version 0.4.8.3 (Beta). In the case of new version :</p>
<p>Replace</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">CURLOPT_SSL_VERIFYPEER <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">CURLOPT_SSL_VERIFYPEER <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span></pre></td></tr></table></div>

<h3>Solution 2:</h3>
<p>Download the <a href="http://curl.haxx.se/docs/caextract.html" target="_blank">.pem</a> file from the cURL site and rename the extension to .crt</p>
<p>Save the renamed file to your web server.</p>
<p>Add the following line to ‘google-api-php-client/src/io/apiCurlIO.php’ right before the ‘curl_exec()’ method call. As per the current version of Google APIs Client Library for PHP, the line of code (‘curl_exec’ method call) is $respData = curl_exec($ch);</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_CAINFO<span style="color: #339933;">,</span> <span style="color: #0000ff;">'c:/path/to/ca-bundle.crt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Remember to replace &#8216;c:/path/to/ca-bundle.crt&#8217; to with the path for your saved .crt file.</p>
<p>Hope everything worked well. Comment below if you face any problems or find any improvements to the script.</p>
<p><center><a href="http://25labs.com/demo/googleplus/" target="_blank"><img style="margin-right: 10px;" src="http://25labs.com/images/view-demo.png" alt="" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px;" src="http://25labs.com/images/download-source.png" alt="" /></a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/tutorial-implementing-google-api-using-oauth-2-0-in-php/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>PageRank November 2011 update: Facebook’s rank downgraded to 9</title>
		<link>http://25labs.com/pagerank-november-2011-update-facebooks-rank-downgraded-to-9/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pagerank-november-2011-update-facebooks-rank-downgraded-to-9</link>
		<comments>http://25labs.com/pagerank-november-2011-update-facebooks-rank-downgraded-to-9/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 13:32:55 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[pagerank]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=137</guid>
		<description><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/11/google-pagerank-updated-420x420.jpg" class="attachment-medium wp-post-image" alt="Google PageRank updated" /></p>Google generally updates the PageRank index either quarterly or once in two months. 8th November 2011 witnessed another PageRank update. The highlight of the update was that Facebook’s PageRank was downgraded to 9 from 10. There may be many reasons for this downgrade. Now Google indexes the comments on Facebook also. It might be one of the [...]]]></description>
				<content:encoded><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/11/google-pagerank-updated-420x420.jpg" class="attachment-medium wp-post-image" alt="Google PageRank updated" /></p><p>Google generally updates the PageRank index either quarterly or once in two months. 8th November 2011 witnessed another PageRank update. The highlight of the update was that Facebook’s PageRank was downgraded to 9 from 10. There may be many reasons for this downgrade. Now Google indexes the comments on Facebook also. It might be one of the reasons for the drop in rank. Another possible reason for the drop in Facebook&#8217;s PageRank could be the increasing number of spam posts and shares. Facebook.com’s PageRank was upgraded to the highest possible PageRank of 10 on 2nd April 2010. Facebook managed to occupy the highest rank for 585 days. Another interesting point is that Google.com which is ranked No: 1 by Alexa in terms of traffic, also has a PageRank of 9. On 27th June 2011, Google downgraded its own rank to 9. Prior to June 2011 update, Google.com had a PageRank of 10. Most of the regional Google sites also suffered drop in their PageRank after June 2011 PageRank update.</p>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/11/facebook-pagerank.jpg"><img class="size-medium wp-image-385 aligncenter" title="Facebook.com's PageRank downgraded to 9" src="http://25labs.com/wp-content/uploads/2011/11/facebook-pagerank-420x230.jpg" alt="Facebook.com's PageRank downgraded to 9" width="420" height="230" /></a></p>
<h3>List of PageRank 10 webpages (After November 2011 update)</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>Title</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>US Goverment website</td>
<td><a href="http://www.usa.gov/" target="_blank">http://www.usa.gov/</a></td>
</tr>
<tr class="odd">
<td>Adobe &#8211; Adobe Reader Download</td>
<td><a href="http://get.adobe.com/reader/" target="_blank">http://get.adobe.com/reader/</a></td>
</tr>
<tr class="even">
<td>Adobe &#8211; Adobe Flash Player Download</td>
<td><a href="http://get.adobe.com/flashplayer/" target="_blank">http://get.adobe.com/flashplayer/</a></td>
</tr>
<tr class="odd">
<td>United States Department of Health and Human Services</td>
<td><a href="http://www.hhs.gov/" target="_blank">http://www.hhs.gov/</a></td>
</tr>
<tr class="even">
<td>Miibeian</td>
<td><a href="http://www.miibeian.gov.cn/" target="_blank">http://www.miibeian.gov.cn/</a></td>
</tr>
<tr class="odd">
<td>Social Bookmarking Sharing Button Widget</td>
<td><a href="http://www.addthis.com/bookmark.php" target="_blank">http://www.addthis.com/bookmark.php</a></td>
</tr>
<tr class="even">
<td>Europeana</td>
<td><a href="http://www.europeana.eu/portal/" target="_blank">http://www.europeana.eu/portal/</a></td>
</tr>
<tr class="odd">
<td>EUA &#8211; European University Association</td>
<td><a href="http://www.eua.be/" target="_blank">http://www.eua.be/</a></td>
</tr>
<tr class="even">
<td>Universitas 21</td>
<td><a href="http://www.universitas21.com/" target="_blank">http://www.universitas21.com/</a></td>
</tr>
</tbody>
</table>
<p>NB: The list may not be complete. If you find a PageRank 10 webpage, please comment on the post so that I can add the link to the list.</p>
<h4><strong>What is PageRank?</strong></h4>
<p>Google’s official statement about PageRank technology:</p>
<p><em>&#8220;PageRank reflects our view of the importance of web pages by considering more than 500 million variables and 2 billion terms. Pages that we believe are important pages receive a higher PageRank and are more likely to appear at the top of the search results.</em></p>
<p><em>PageRank also considers the importance of each page that casts a vote, as votes from some pages are considered to have greater value, thus giving the linked page greater value. We have always taken a pragmatic approach to help improve search quality and create useful products, and our technology uses the collective intelligence of the web to determine a page&#8217;s importance.&#8221;</em></p>
<p>Please note that Google had removed this official definition from their website. Earlier they had this definition in their technology overview page.</p>
<p>PageRank is a score that ranges from 0 to 10. The most popular websites have a PageRank of 10. The least have a PageRank of 0. Another point to note is that PageRank is not for a website. But it is for a webpage. If there are 100 webpages in a website, then all the 100 pages will be ranked separately. That is, www.xyz.com and www.xyz.com/abc/ may have different ranks.</p>
<p>Many webmasters think that PageRank is the only criteria used to determine a webpage’s position in Google search results. But in reality, Google considers about 200 factors to determine the position of a webpage’s position. PageRank is just one of them. This is clear from the above fact that Google.com and Facebook.com which occupies the first and second spot in terms of traffic has PageRank of 9, while many other sites which are less popular has a PageRank of 10.</p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/pagerank-november-2011-update-facebooks-rank-downgraded-to-9/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tutorial: Integrate Facebook Connect to your website using PHP SDK v.3.x.x which uses Graph API</title>
		<link>http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api</link>
		<comments>http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 18:44:16 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web designing]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=108</guid>
		<description><![CDATA[<p><img width="265" height="286" src="http://25labs.com/wp-content/uploads/2011/09/facebook-deveploper-application-icon.png" class="attachment-medium wp-post-image" alt="facebook-deveploper-application-icon" /></p>Now-a-days it is common for websites to have Facebook Connect integrated to it. Facebook Connect is the iteration of Facebook Platform that allows users to ‘connect’ their Facebook identity, friends and privacy to any site. It enables a website to implement features of Facebook platform on it. Facebook Connect has been around since May 2008. [...]]]></description>
				<content:encoded><![CDATA[<p><img width="265" height="286" src="http://25labs.com/wp-content/uploads/2011/09/facebook-deveploper-application-icon.png" class="attachment-medium wp-post-image" alt="facebook-deveploper-application-icon" /></p><p>Now-a-days it is common for websites to have Facebook Connect integrated to it. Facebook Connect is the iteration of Facebook Platform that allows users to ‘connect’ their Facebook identity, friends and privacy to any site. It enables a website to implement features of Facebook platform on it. Facebook Connect has been around since May 2008. Since then, Facebook has released various Software development kits (SDK) namely JavaScript SDK, PHP SDK, iOS SDK (iPhone &amp; iPad) and Android SDK for easy implementation of their API. In this tutorial we will be concentrating on PHP SDK. As of today, the latest version of PHP SDK is 3.1.1 which was released on August 10, 2011. PHP SDK v3.x.x is a major update from v2.2.x, as the new SDK uses OAuth authentication flows instead of Facebook’s legacy authentication flow. The new SDK has two classes. The first (BaseFacebook) maintains the core of the upgrade, and the second one (Facebook) is a subclass that uses PHP sessions to store the user id and access token.</p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/facebook-deveploper-application-icon.png"><img class="alignright size-thumbnail wp-image-300" title="facebook-deveploper-application-icon" src="http://25labs.com/wp-content/uploads/2011/09/facebook-deveploper-application-icon-139x151.png" alt="" width="139" height="151" /></a>Facebook has made it clear that, all website and canvas apps must exclusively support OAuth 2.0 (draft 20) by October 1, 2011. The OAuth 2.0 authorization protocol enables a third-party application to obtain limited access to an HTTP service, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and the HTTP service, or by allowing the third-party application to obtain access on its own behalf. Facebook insists all canvas apps to use the ’signed_request’ parameter. Because of this, it is mandatory for all developers to migrate to new version (v3.x.x) as older versions will stop working from October 1, 2011.</p>
<p><center><a href="http://25labs.com/demo/fb/" target="_blank"><img style="margin-right: 10px;" src="http://25labs.com/images/view-demo.png" alt="" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px;" src="http://25labs.com/images/download-source.png" alt="" /></a></center></p>
<h2>Registering your application</h2>
<p>Steps 1 to 3 will explain the procedure of registering the application at Facebook. You need to register at Facebook and obtain App ID and App Secret, for the application to work.</p>
<h3>Step 1:</h3>
<p>The primary step is to visit <a title="Facebook Developer" href="http://developers.facebook.com/apps" target="_blank">http://developers.facebook.com/apps</a>.</p>
<p>If you are visiting this URL for the first time, you will have a window similar to the one shown below in which Facebook developer app will request your permission to access your basic information.</p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/developer-app-permission-request.jpg"><img class="aligncenter size-medium wp-image-308" title="developer-app-permission-request" src="http://25labs.com/wp-content/uploads/2011/09/developer-app-permission-request-420x241.jpg" alt="" width="420" height="241" /></a></p>
<p>Click the ‘Allow’ button.</p>
<h3>Step 2:</h3>
<p>Now you be on a page that shows you your recently viewed app. Don’t worry if it doesn’t show any app. It just means that you haven’t created any app yet.</p>
<p>Now, click ‘Create New App’ button.</p>
<div id="attachment_307" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/create-new-app.jpg"><img class="size-medium wp-image-307" title="create-new-app" src="http://25labs.com/wp-content/uploads/2011/09/create-new-app-420x242.jpg" alt="Create New App" width="420" height="242" /></a><p class="wp-caption-text">Create New App</p></div>
<p>In the window that pops up, enter the name of your application. Mark the check box ‘I agree to Facebook Terms’ and click ‘Continue’ button.</p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/new-app-name.jpg"><img class="aligncenter size-medium wp-image-309" title="new-app-name" src="http://25labs.com/wp-content/uploads/2011/09/new-app-name-420x153.jpg" alt="" width="420" height="153" /></a></p>
<p>Now you may be asked to solve a captcha which verifies that you are human.</p>
<h3>Step 3:</h3>
<p>You will be taken to the application basic settings page.</p>
<p>On the top portion of the page you will have your ‘App ID’ and ‘App Secret’. Please note them as we will need them in Step 5.</p>
<p>Enter your domain name as ‘App Domain’. Please note that a ‘your-domain.com’ will include ‘*.your-domain.com’ also. That is, you can use the app on any of your sub-domains. You can even enter ‘localhost’ if you are testing your application on your local machine.</p>
<p>In the ‘Website’ section, you need to enter ‘Site URL’. ‘Site URL’ will be entry page for your application. As we are making a webpage that has f-connect enabled, we need to give the address of the webpage that we are about to make. In my case, it is <a href="http://25labs.com/demo/fb/index.php" target="_blank">http://25labs.com/demo/fb/index.php</a>. Site URL will be the redirect URL for your application. Because of security reasons, Facebook will redirect users to this URL only. We will be creating webpage in the later sections. If you are not sure about what your URL will be, just leave the field blank as you can fill it any time later.</p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/application-basic-settings.jpg"><img class="aligncenter size-medium wp-image-306" title="application-basic-settings" src="http://25labs.com/wp-content/uploads/2011/09/application-basic-settings-420x371.jpg" alt="" width="420" height="371" /></a> Now click ‘Save Changes’.</p>
<p>The registration of your application is now complete. Now we will move on to build our application.</p>
<h2>Downloading PHP SDK</h2>
<p>Facebook releases its PHP Software Development kit so that developers can easily integrate their Graph API to the applications.</p>
<h3>Step 4:</h3>
<p>Download the latest version of PHP SDK from <a title="GitHub Facebook PHP SDK" href="https://github.com/facebook/php-sdk" target="_blank">GitHub</a>.</p>
<p>Extract the compressed file and you will find folders and files similar to the one shown below.</p>
<div id="attachment_334" class="wp-caption aligncenter" style="width: 249px"><a href="http://25labs.com/wp-content/uploads/2011/09/php-sdk-folder-structure.jpg"><img class="size-full wp-image-334" title="php-sdk-folder-structure" src="http://25labs.com/wp-content/uploads/2011/09/php-sdk-folder-structure.jpg" alt="PHP SDK folder structure" width="239" height="239" /></a><p class="wp-caption-text">PHP SDK folder structure</p></div>
<p>Upload the above shown folders to the webhost where you wish to have your webpage. In my case it is ‘25labs.com/demo/fb/’. For the application to run, only the folder ‘src’ is required. All other files and folders are examples, tests, logs etc and so they can be optionally discarded.</p>
<h2>Creating the access file (fbaccess.php)</h2>
<p>Create a file ’fbaccess.php’.</p>
<p>In steps 5 to 10, I will explain the file part by part.</p>
<h3>Step 5:</h3>
<p>The first part is Application Configurations. In this part we have 3 variables &#8211; $app_id, $app_secret, and $base_url.</p>
<p>Replace ‘Your App ID/API Key goes here’ and ‘Your App secret goes here’ with the ‘App ID’ and ‘App Secret’ that you created in Step 3, respectively.</p>
<p>Replace ‘Your Site URL goes here’ with the ‘Site URL’ that you entered in Step 3. If you are still not sure of your site URL, leave it as such. You can come back and edit it after step 11.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$app_id</span>		<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your App ID/API Key goes here&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$app_secret</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your App secret goes here&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$site_url</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your Site URL goes here&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Step 6:</h3>
<p>Now, include ‘facebook.php’ which can be found in the ‘src’ folder of PHP SD that you downloaded.</p>
<p>Then you need to create an application instance using the constructor of class ‘Facebook’. The App ID and App Secret need to be passed as arguments for the constructor. In earlier versions of PHP SDK (v2.x.x), the argument array had an optional key ‘session’. But in v3.x.x, ‘session’ key is not used at all.</p>
<p>Then we call the function getUser() which will return the user ID. We will be using a variable ‘$user’ to store the User ID of Facebook user. We may or may not have this data based on whether the user is logged in. If we have a $user id here, it means we know the user is logged into Facebook, but we don&#8217;t know if the access token is valid. An access token is invalid if the user logged out of Facebook.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;src/facebook.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'appId'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$app_id</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'secret'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$app_secret</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Step 7:</h3>
<p>If we get a User ID in the previous step, it means that we have a logged in user. Now we need to check whether the logged in user is authenticated to run the application.</p>
<p>For this, we call the ‘api’ function with value ‘/me’. If the user is authenticated, api(‘/me’) will return the profile information of the user. If the user is not authenticated, the function will produce an exception. We catch this exception and then make the ‘$user’ variable NULL so that the user can be asked to authenticate.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//==================== Single query method ======================================</span>
	try<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Proceed knowing you have a logged in user who's authenticated.</span>
		<span style="color: #000088;">$user_profile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//==================== Single query method ends =================================</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This try catch-block is also an example for single query method. Different arguments can be used for function ‘api’ to return various results for authenticated users in single query method. Full set of arguments can be found at <a href="https://developers.facebook.com/docs/reference/api/" target="_blank">https://developers.facebook.com/docs/reference/api/</a></p>
<h3>Step 8:</h3>
<p>After Step 7, variable ‘$user’ will hold Facebook User ID if we have a logged in authenticated user, and NULL otherwise.</p>
<p>If it holds a User ID, it means that the user is logged into the application. So we need a logout URL. If the variable is NULL, it means that user is not logged in and we need a login URL.</p>
<p>We use functions getLoginUrl() and getLogoutUrl() to get the login and logout URL respectively. The argument for getLoginUrl() is an array with optional keys ‘scope’ and ‘redirect_uri’.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'scope'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Your list of Permissions'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Permissions to request from the user</span>
		<span style="color: #0000ff;">'redirect_uri'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Your Site URL'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// URL to redirect the user to once the login/authorization process is complete.</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The ‘scope’ field will contain a comma separated list of permissions to request from the user. You must ask for all the permissions that you need for the app to work. For example, if you need email, birthday and location of the user, then you must specify ‘email, user_birthday,user_location’ in the scope field. In my case, I need permission to retrieve news feed, publish stream, birthday, location, work history, hometown and user photos. Thus my ‘scope’ parameter is &#8216;read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos&#8217;. You can read about the full list of permissions at <a href="https://developers.facebook.com/docs/reference/api/permissions/" target="_blank">https://developers.facebook.com/docs/reference/api/permissions/</a>.</p>
<p>‘redirect_uri’ field will contain the URL to redirect the user to, once the login/authorization process is complete. The user will be redirected to the URL on both login success and failure. If this property is not specified, the user will be redirected to the current URL (i.e. the URL of the page where this method was called, typically the current URL in the user&#8217;s browser).</p>
<p>The argument for getLogoutUrl() is an optional array with key ‘next’ which contain Next URL to which to redirect the user after logging out.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$logoutUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogoutUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'next'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Your Redirect URL after logout'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// URL to which to redirect the user after logging out</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Please note that it should be an absolute URL. If this property is not specified, the user will be redirected to the current URL.</p>
<p>For my application webpage, the complete code for login and logout URL is shown below.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get logout URL</span>
	<span style="color: #000088;">$logoutUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogoutUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get login URL</span>
	<span style="color: #000088;">$loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'scope'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Step 9:</h3>
<p>Now we need to retrieve the information that we need if we have a logged in authenticated user. For that we can use the single query method mentioned in Step 7. The below code retrieve user info, news feed, friends list and photos of the logged in user. You can also specify an optional limit for many queries.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">try<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user_info</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$feed</span>		<span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/home?limit=50'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friends_list</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$photos</span>		<span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/photos?limit=6'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can notice that it takes 4 requests to the graph API. It can slow down the page significantly and also increase the load. So it will be better if we can combine all these requests. For that we use Batch requests. All the queries can be saved to an array. We encode the array as JSON and POST this JSON to batch endpoint on the graph. It will return values that are indexed in order of the original array. The content will be in ['body'] as a JSON and we need to decode the JSON to get the results as a PHP array. Batch query replacement for single query method is shown below.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//========= Batch requests over the Facebook Graph API using the PHP-SDK ========</span>
	<span style="color: #666666; font-style: italic;">// Save your method calls into an array</span>
	<span style="color: #000088;">$queries</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/home?limit=50'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/photos?limit=6'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// POST your queries to the batch endpoint on the graph.</span>
	try<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$batchResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?batch='</span><span style="color: #339933;">.</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$o</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$o</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Return values are indexed in order of the original array, content is in ['body'] as a JSON</span>
	<span style="color: #666666; font-style: italic;">//string. Decode for use as a PHP array.</span>
	<span style="color: #000088;">$user_info</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$feed</span>			<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friends_list</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$photos</span>			<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//========= Batch requests over the Facebook Graph API using the PHP-SDK ends =====</span></pre></td></tr></table></div>

<h3>Step 10:</h3>
<p>You can update user’s status by using the method mentioned below. We POST the status to ‘/UserID/feed’. (&#8216;UserID&#8217; to be replaced with the required user&#8217;s ID). The status to be posted is an array with optional fields &#8211; message, link, picture, name, caption, and description.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$publishStream</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$user</span>/feed&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'message'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Check out 25 labs'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'link'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://25labs.com'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'picture'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://25labs.com/images/25-labs-160-160.jpg'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'name'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'25 labs'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'caption'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'25labs.com'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'description'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'A Technology Laboratory. Highly Recomented technology blog.'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you just want a status message, then just omit all other fields.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">try<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$statusUpdate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$user</span>/feed&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Your Status goes here'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2 style="padding-bottom: 0px;">Complete fbaccess.php for my webpage</h2>
<h2 style="padding-top: 0px;">(Codes in Step 5 to 10 combined)</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//Application Configurations</span>
<span style="color: #000088;">$app_id</span>		<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your App ID/API Key goes here&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$app_secret</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your App secret goes here&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$site_url</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Your Site URL goes here&quot;</span><span style="color: #339933;">;</span>
&nbsp;
try<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;src/facebook.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Create our application instance</span>
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'appId'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$app_id</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'secret'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$app_secret</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get User ID</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// We may or may not have this data based</span>
<span style="color: #666666; font-style: italic;">// on whether the user is logged in.</span>
<span style="color: #666666; font-style: italic;">// If we have a $user id here, it means we know</span>
<span style="color: #666666; font-style: italic;">// the user is logged into</span>
<span style="color: #666666; font-style: italic;">// Facebook, but we don’t know if the access token is valid. An access</span>
<span style="color: #666666; font-style: italic;">// token is invalid if the user logged out of Facebook.</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//==================== Single query method ======================================</span>
	try<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Proceed knowing you have a logged in user who's authenticated.</span>
		<span style="color: #000088;">$user_profile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//==================== Single query method ends =================================</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get logout URL</span>
	<span style="color: #000088;">$logoutUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLogoutUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get login URL</span>
	<span style="color: #000088;">$loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'scope'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'redirect_uri'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$site_url</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Proceed knowing you have a logged in user who has a valid session.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//========= Batch requests over the Facebook Graph API using the PHP-SDK ========</span>
	<span style="color: #666666; font-style: italic;">// Save your method calls into an array</span>
	<span style="color: #000088;">$queries</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/home?limit=50'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/friends'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'relative_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/photos?limit=6'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// POST your queries to the batch endpoint on the graph.</span>
	try<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$batchResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?batch='</span><span style="color: #339933;">.</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$o</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$o</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Return values are indexed in order of the original array, content is in ['body'] as a JSON</span>
	<span style="color: #666666; font-style: italic;">//string. Decode for use as a PHP array.</span>
	<span style="color: #000088;">$user_info</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$feed</span>			<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$friends_list</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$photos</span>			<span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$batchResponse</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//========= Batch requests over the Facebook Graph API using the PHP-SDK ends =====</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Update user's status using graph api</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'publish'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		try<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$publishStream</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$user</span>/feed&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'message'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Check out 25 labs'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'link'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://25labs.com'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'picture'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://25labs.com/images/25-labs-160-160.jpg'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'name'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'25 labs'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'caption'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'25labs.com'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'description'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'A Technology Laboratory. Highly Recomented technology blog.'</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Update user's status using graph api</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		try<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$statusUpdate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$user</span>/feed&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>catch<span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h2>Creating the main webpage</h2>
<p>Now we will be creating the main page of the website. It will be the one that is visible to the users.</p>
<h3>Step 11:</h3>
<p>Create a PHP file (In my case it is index.php).</p>
<p>Include ‘fbaccess.php’ into it.</p>
<p>‘fbaccess.php’ will give you a NULL ‘$user’ variable and ‘$loginUrl’ for a user who is not logged in and authenticated. So, if ‘$user’ is not set, make a login button or link and make ‘$loginUrl’ its destination. User can click this button and login to your webpage.</p>
<p>If ‘$user’ is set (logged in authenticated user), ‘fbaccess.php’ will give you 5 variables &#8211; $logoutUrl, $user_info, $feed, $friends_list, and $photos. Except $logoutUrl, all others are PHP arrays.</p>
<p>If you print the array ‘$user_info’ it will look something similar to this.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="plain" style="font-family:monospace;">Array
(
    [id] =&gt; 100002936955841
    [name] =&gt; Unni Krishnan
    [first_name] =&gt; Unni
    [last_name] =&gt; Krishnan
    [link] =&gt; http://www.facebook.com/profile.php?id=100002936955841
    [birthday] =&gt; 01/02/1988
    [hometown] =&gt; Array
        (
            [id] =&gt; 110383752315912
            [name] =&gt; Trivandrum, India
        )
    [gender] =&gt; male
    [timezone] =&gt; 5.5
    [locale] =&gt; en_US
    [updated_time] =&gt; 2011-09-18T14:16:25+0000
)</pre></td></tr></table></div>

<p>You can use these variables which has all the information you need, to make your webpage. Please note that user’s first name, last name and profile picture are publicly available and you don’t need PHP SDK or an access token to retrieve them.</p>
<p>The below mentioned link can be used to get the profile picture of a user.</p>
<p><a href="https://graph.facebook.com/zuck /picture?type=large" target="_blank">https://graph.facebook.com/zuck /picture?type=large</a></p>
<p>In the above example ‘zuck’ is Mark Zuckerberg’s username.</p>
<p>You can specify the picture size you want with the ‘type’ argument, which should be one of square (50&#215;50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), and large (about 200 pixels wide, variable height).</p>
<p>When complete, upload the page to the host where you need your f-connect enabled website need to be. Please not the URL of the page as it will act as your site URL. If you had skipped to enter the Site URL in Step 3 and 5, please go back and enter them.</p>
<p>You can download the complete source of my demo webpage from <a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank">here</a>.</p>
<h3>User Authentication</h3>
<p>When a user login at your webpage for the first time, he will have to grant permission for accessing his details. It will look similar to this.</p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/25labs-permission-request.jpg"><img class="aligncenter size-medium wp-image-329" title="25labs-permission-request" src="http://25labs.com/wp-content/uploads/2011/09/25labs-permission-request-420x308.jpg" alt="" width="420" height="308" /></a></p>
<p>Once the user clicks ‘Allow’ he will be redirected to your webpage as an authenticated user.</p>
<h2>Issues you may face</h2>
<p>Any errors that you get will be logged in your hosts error log. Please check log to get information on errors, if any.</p>
<h3>Session Error:</h3>
<p>You may get a similar warning in your error log.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="plain" style="font-family:monospace;">Warning: session_start() [&lt;a href='function.session-start'&gt;function.session-start&lt;/a&gt;]:
Cannot send session cookie - headers already sent</pre></td></tr></table></div>

<p>In this case getUser() function will return 0 for all users even if they are logged in. This happens because session doesn’t get saved in your host.</p>
<h3>Solution:</h3>
<p>Make sure the session.save_path in php.ini is set and point to a valid path. In many hosts the line session.save_path would be commented out. In that case please uncomment the line.</p>
<p>Hope everything worked well. Comment below if you face any problems or find any improvements to the script.</p>
<p><center><a href="http://25labs.com/demo/fb/" target="_blank"><img style="margin-right: 10px;" src="http://25labs.com/images/view-demo.png" alt="" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px;" src="http://25labs.com/images/download-source.png" alt="" /></a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/feed/</wfw:commentRss>
		<slash:comments>368</slash:comments>
		</item>
		<item>
		<title>A quarter of mobile phones sold are smartphones and almost half of the smartphones have android OS</title>
		<link>http://25labs.com/a-quarter-of-mobile-phones-sold-are-smartphones-and-almost-half-of-the-smartphones-have-android-os/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-quarter-of-mobile-phones-sold-are-smartphones-and-almost-half-of-the-smartphones-have-android-os</link>
		<comments>http://25labs.com/a-quarter-of-mobile-phones-sold-are-smartphones-and-almost-half-of-the-smartphones-have-android-os/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 06:14:05 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Mobile phone]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[blackberry]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile phone]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[symbian]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=89</guid>
		<description><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/smartphone-android-symbian-ios-rim-windows-mobile-os-logos-420x420.jpg" class="attachment-medium wp-post-image" alt="Android - Symbian - iOS - Windows Mobile logos" /></p>1.6 billion Mobile phones were sold in 2010. Sales grew by 32% in 2010. Sales in 2011 have crossed 8.5 billion in first two quarters of the year. If the current trend continues, it is expected to cross 1.7 billion by year end. About 4.5 million handsets are sold every day. Nokia occupies the top [...]]]></description>
				<content:encoded><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/smartphone-android-symbian-ios-rim-windows-mobile-os-logos-420x420.jpg" class="attachment-medium wp-post-image" alt="Android - Symbian - iOS - Windows Mobile logos" /></p><p>1.6 billion Mobile phones were sold in 2010. Sales grew by 32% in 2010. Sales in 2011 have crossed 8.5 billion in first two quarters of the year. If the current trend continues, it is expected to cross 1.7 billion by year end. About 4.5 million handsets are sold every day.</p>
<p>Nokia occupies the top spot in mobile phone vendors followed by Samsung, LG and Apple. Nokia’s share in smartphones is decreasing day by day. The main reason is that, till date it doesn’t have a smartphone that run on android. All other vendors are moving to android platform which is today’s hottest pick. I am a great fan of Nokia mainly because of its quality and am looking forward for a Nokia &#8211; Android smartphone.</p>
<h3>Mobile phone sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-phone-sales.jpg"><img class="aligncenter size-medium wp-image-255" title="Mobile phone sales" src="http://25labs.com/wp-content/uploads/2011/09/mobile-phone-sales-420x246.jpg" alt="Mobile phone sales" width="420" height="246" /></a></p>
<p>In mobile handset sales, Nokia has a market share of 23%. The second spot is occupied by Samsung which has 16% market share. LG and Apple have 6% and 5% respectively.</p>
<h3>Mobile vendors market share &#8211; Q2 2011:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-vendors-market-share-q2-2011.jpg"><img class="aligncenter size-medium wp-image-256" title="Mobile vendors market share - Q2 2011" src="http://25labs.com/wp-content/uploads/2011/09/mobile-vendors-market-share-q2-2011-420x342.jpg" alt="Mobile vendors market share - Q2 2011" width="420" height="342" /></a></p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/smartphone-android-symbian-ios-rim-windows-mobile-os-logos.jpg"><img class="alignright size-medium wp-image-280" title="Android - Symbian - iOS - Windows Mobile logos" src="http://25labs.com/wp-content/uploads/2011/09/smartphone-android-symbian-ios-rim-windows-mobile-os-logos-420x420.jpg" alt="Android - Symbian - iOS - Windows Mobile logos" width="252" height="252" /></a>Today more than 25% of the mobile phones sold are smartphones. This share is expected to touch 60% in couple of years. More than a hundred million smart phones were sold in second quarter of 2011 (April –June 2011). That is, about 14 smartphones are sold per second around the globe. The major players in smartphone business are Nokia, Samsung, LG, Apple and BlackBerry. Most of the Nokia smartphones runs on Symbian platform. The Symbian platform is the successor to Symbian OS and Nokia Series 60. In late 2009, Samsung introduced the Bada operating system for smartphones. They started rolling out phones with Bada OS in June 2010. Samsung doesn’t concentrate on a particular OS for their smartphones. They have android phones, windows phones etc. Apple’s iPhone runs on iOS (known as iPhone OS before June 2010). Research In Motion Limited makes operating system for BlackBerry and the OS is popularly known as RIM.</p>
<h3> Smart phone sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/smartphone-sales.jpg"><img class="aligncenter size-medium wp-image-259" title="Smartphone sales" src="http://25labs.com/wp-content/uploads/2011/09/smartphone-sales-420x265.jpg" alt="Smartphone sales" width="420" height="265" /></a></p>
<h3>Share of Smartphones:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/share-of-smartphones.jpg"><img class="aligncenter size-medium wp-image-257" title="Share of smartphones chart" src="http://25labs.com/wp-content/uploads/2011/09/share-of-smartphones-420x270.jpg" alt="Share of smartphones chart" width="420" height="270" /></a></p>
<p>In second quarter of 2011, Android leads the smartphone operating system market with 43% share. Then comes Symbian with 22% followed by iOS with 18% and Research In Motion with 12%. Microsoft Windows mobile had a share of just 2% and all others put together totals to 3%.</p>
<h3>Smartphone operating system market share &#8211; Q2 2011:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-os-market-share-august-2011.jpg"><img class="aligncenter size-medium wp-image-254" title="Mobile OS market share - August 2001" src="http://25labs.com/wp-content/uploads/2011/09/mobile-os-market-share-august-2011-420x390.jpg" alt="Mobile OS market share - August 2001" width="420" height="390" /></a></p>
<p>Till the last quarter of 2010, Symbian was the leading smartphone OS. In January 2011 both Symbian and Android had almost equal share in mobile OS market. Six months later, that is, in second quarter of 2011 Android had double the market share of Symbian. This shows how aggressive Android is, in gobbling up Symbian market share. In this period Android market share increased from 31% to 43% and Symbian market share decreased from 33% to just 22%. When Android was born, more than 50% of smartphones ran on Symbian platform. With in just 3 years of its launch, Android is all set to break 50% mark in smartphone market. If the current trend continues, we can expect it in Q3 2011. As of today, more than 6 android powered mobile phones are sold each second. That is, more than half a million android phones are sold around the globe, in a day. And this number is continuously on the rise.</p>
<h3>Smartphone OS market share:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-os-market-share.jpg"><img class="aligncenter size-medium wp-image-253" title="Mobile OS market share graph" src="http://25labs.com/wp-content/uploads/2011/09/mobile-os-market-share-420x231.jpg" alt="Mobile OS market share graph" width="420" height="231" /></a></p>
<h3>Android mobile sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/android-mobile-sales.jpg"><img class="aligncenter size-medium wp-image-250" title="Android mobile sales graph" src="http://25labs.com/wp-content/uploads/2011/09/android-mobile-sales-420x241.jpg" alt="Android mobile sales graph" width="420" height="241" /></a></p>
<h3>Symbian smartphone sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/symbian-sales.jpg"><img class="aligncenter size-medium wp-image-260" title="Symbian sales" src="http://25labs.com/wp-content/uploads/2011/09/symbian-sales-420x229.jpg" alt="Symbian sales" width="420" height="229" /></a></p>
<p>Apple&#8217;s iPhone has shown increase in sales, but its market share has remained more or less, the same. This is because the increase in sales of iPhone is just not enough to match the increase in Android phones. If Apple doesn’t modify its iOS to match the Android, we can expect a dip in iPhone sales in coming months. With iPhone 5 around the corner, we can expect a change in market share. In Q2 2011, iPhone sales increased by 125%, but the increase in market share was just 28%. In this period, Android sales rose by 341% and its market share increased by 152%.</p>
<h3>iPhone sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/iphone-sales.jpg"><img class="aligncenter size-medium wp-image-252" title="iPhone sales graph" src="http://25labs.com/wp-content/uploads/2011/09/iphone-sales-420x242.jpg" alt="iPhone sales graph" width="420" height="242" /></a></p>
<p>The market share of Research In Motion (BlackBerry) and Microsoft Windows mobile has decreased considerable over the years. BlackBerry was once considered just for business users. Now-a-days smartphones are not just for business guys. They are used for entertainment purpose too. It is tough for BlackBerry to get rid of that business image. They are trying hard through TV commercials to make people understand that BlackBerry is not just for big guns. Microsoft also needs to pull up their socks if they don’t wish to continue losing its market share. They need to make their OS attractive and user friendly. More features need to be incorporated into Windows Mobile and newer versions and updates should be released more frequently.</p>
<h3>BlackBerry sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/blackberry-sales.jpg"><img class="aligncenter size-medium wp-image-251" title="BlackBerry sales graph" src="http://25labs.com/wp-content/uploads/2011/09/blackberry-sales-420x238.jpg" alt="BlackBerry sales graph" width="420" height="238" /></a></p>
<h3>Windows Mobile sales:</h3>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/windows-mobile-sales.jpg"><img class="aligncenter size-medium wp-image-261" title="Windows mobile sales" src="http://25labs.com/wp-content/uploads/2011/09/windows-mobile-sales-420x238.jpg" alt="Windows mobile sales" width="420" height="238" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/a-quarter-of-mobile-phones-sold-are-smartphones-and-almost-half-of-the-smartphones-have-android-os/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Browser wars: Rise of Google Chrome and decline of Internet Explorer</title>
		<link>http://25labs.com/browser-wars-rise-of-google-chrome-and-decline-of-internet-explorer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=browser-wars-rise-of-google-chrome-and-decline-of-internet-explorer</link>
		<comments>http://25labs.com/browser-wars-rise-of-google-chrome-and-decline-of-internet-explorer/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 00:22:50 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[internet explorer]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=69</guid>
		<description><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/web-browser-logos-420x420.jpg" class="attachment-medium wp-post-image" alt="web-browser-logos" /></p>For more than a decade, Internet Explorer has remained at the top spot in Web Browser statistics. The first version of Windows Internet Explorer was launched on 16 August 1995. Its usage share rose to 95% in 2003. First version of Mozilla Firefox was launched in 2005 and since then the decline of Internet Explorer [...]]]></description>
				<content:encoded><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/web-browser-logos-420x420.jpg" class="attachment-medium wp-post-image" alt="web-browser-logos" /></p><p>For more than a decade, Internet Explorer has remained at the top spot in Web Browser statistics. The first version of Windows Internet Explorer was launched on 16 August 1995. Its usage share rose to 95% in 2003. First version of Mozilla Firefox was launched in 2005 and since then the decline of Internet Explorer started. In 2008, the first version of Google Chrome was launched which added fuel to the decline of Internet Explorer.</p>
<p>The usage share of web browsers for the month of August 2011 is out. First on the list is Internet Explorer, followed by Mozilla Firefox, Google Chrome and Safari.</p>
<h3 style="text-align: center;">Web Browser Usage Share &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/web-browser-usage-share-aug-2011.jpg"><img class="aligncenter size-medium wp-image-216" title="web-browser-usage-share-aug-2011" src="http://25labs.com/wp-content/uploads/2011/09/web-browser-usage-share-aug-2011-420x398.jpg" alt="" width="420" height="398" /></a></p>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/web-browser-logos.jpg"><img class="size-thumbnail wp-image-237 alignright" title="web-browser-logos" src="http://25labs.com/wp-content/uploads/2011/09/web-browser-logos-151x151.jpg" alt="" width="151" height="151" /></a>Internet Explorer still occupies the top spot, mainly because it comes bundled with Windows. A non-techie will prefer to use the default browser installed, rather than installing a custom one. A techie will probably prefer a custom browser. This is clear from the fact that a technical website will receive only about 10-15% of visits from Internet Explorer. This is significantly a lower number compared to the global average of 42%.</p>
<p>Over the past 1 year, the usage share of Google Chrome has increased from 10.76% to 23.16%. In the same period Internet Explorer users declined from 51.34% to 41.89%. Mozilla Firefox’s usage share also declined from 31.09% to 27.49%.</p>
<p>The chart below shows the usage share of various web browsers, month on month since July 2008.</p>
<h3>Web Browser usage share: July 2008 &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/web-browser-usage-share.jpg"><img class="aligncenter size-medium wp-image-215" title="web-browser-usage-share" src="http://25labs.com/wp-content/uploads/2011/09/web-browser-usage-share-420x221.jpg" alt="" width="420" height="221" /></a></p>
<p>Internet Explorer is the biggest loser. It had almost 70% usage share in July 2008. But now, its share is just over 40%. The chart below is self explanatory.</p>
<h3>Internet Explorer usage share: July 2008 &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/internet-explorer-usage-share.jpg"><img class="aligncenter size-medium wp-image-210" title="internet-explorer-usage-share" src="http://25labs.com/wp-content/uploads/2011/09/internet-explorer-usage-share-420x194.jpg" alt="" width="420" height="194" /></a></p>
<p>When we consider the period July 2008 to Aug 2011, the usage of Mozilla Firefox has increased from 26.14% to 27.49%, a marginal increase. But, if we analyze the stats closely, we can find that Firefox’s share rose from 26.14% to 32.21% for the period July 2008 to November 2009. Since November 2009, there has been a gradual decrease in the usage share.</p>
<h3>Mozilla Fifefox usage share: July 2008 &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/mozilla-firefox-usage-share.jpg"><img class="aligncenter size-medium wp-image-213" title="mozilla-firefox-usage-share" src="http://25labs.com/wp-content/uploads/2011/09/mozilla-firefox-usage-share-420x213.jpg" alt="" width="420" height="213" /></a></p>
<p>Since the launch of Google Chrome on 02 September 2008, there has been an exponential rise in Chrome’s usage share. The only month in which Chrome had a decline was November 2008 mainly because it was in beta stage for the first three months of its launch &#8211; September, October and November 2008. The stable version of Google Chrome was released on 11 December, 2008. It is very much impressive to not that Chrome has grabbed 23% usage share in just 3 years. The chart below shows an exponential growth for Google Chrome.</p>
<h3>Google Chrome usage share: July 2008 &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/google-chrome-usage-share.jpg"><img class="aligncenter size-medium wp-image-209" title="google-chrome-usage-share" src="http://25labs.com/wp-content/uploads/2011/09/google-chrome-usage-share-420x213.jpg" alt="" width="420" height="213" /></a></p>
<p>Safari’s usage has increased from 3.3% to 5.19% over the period. A significant percentage of Safari users are Mac users as Safari is the preinstalled web browser in Mac. Number of users for Safari is very low compared to the Internet explorer, Firefox and Chrome.</p>
<h3>Safari usage share: July 2008 &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/safari-usage-share.jpg"><img class="aligncenter size-medium wp-image-214" title="safari-usage-share" src="http://25labs.com/wp-content/uploads/2011/09/safari-usage-share-420x213.jpg" alt="" width="420" height="213" /></a><br />
Over the past three years, the number of mobile web users has increased tremendously. Mobile web users which were negligible in 2008, has rose to 7.12% in August 2011. High speed internet on phone has become affordable and so gained popularity in recent years.</p>
<h3>Mobile Web Users</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-web-browser.jpg"><img class="aligncenter size-medium wp-image-233" title="mobile-web-browser" src="http://25labs.com/wp-content/uploads/2011/09/mobile-web-browser-420x239.jpg" alt="" width="420" height="239" /></a></p>
<p>The most popular mobile browser is Opera Mini closely followed by Android browser. As of August 2011 stats, 21.6% of mobile web users use Opera Mini and 19.71% use Android browser. They are followed by Nokia browser, iPhone browser and Black Beery browser with 16.98%, 14.9% and 11.63% respectively.</p>
<h3>Mobile Browser user share &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-browser-usage-share-aug-2011.jpg"><img class="aligncenter size-medium wp-image-211" title="mobile-browser-usage-share-aug-2011" src="http://25labs.com/wp-content/uploads/2011/09/mobile-browser-usage-share-aug-2011-420x359.jpg" alt="" width="420" height="359" /></a></p>
<p>Since the launch of Android operating system, it has gained so much popularity and many are switching to android phones. It has led to decline in iPhones and so iPhone web browser. Since December 2008, iPhone web user share declined from 21.68% to 14.90% and Opera Mini user share from 26.51% to 21.60%. In this period Android web user share rose to 19.71% from null. In one or two months, we can expect android browser to overtake Opera Mini.</p>
<h3>Mobile web Browser user share: December 2008 &#8211; August 2011</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/mobile-web-browser-usage-share.jpg"><img class="aligncenter size-medium wp-image-212" title="mobile-web-browser-usage-share" src="http://25labs.com/wp-content/uploads/2011/09/mobile-web-browser-usage-share-420x225.jpg" alt="" width="420" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/browser-wars-rise-of-google-chrome-and-decline-of-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Import Gmail or Google contacts using Google Contacts Data API and OAuth 2.0 in PHP</title>
		<link>http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php</link>
		<comments>http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 21:41:48 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Web Designing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web designing]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=41</guid>
		<description><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/oauth-gmail-logo-420x420.jpg" class="attachment-medium wp-post-image" alt="oauth-gmail-logo" /></p>First, let me introduce what Contacts Data API and OAuth is. OAuth OAuth (Open Authorization) is an open standard for authorization. It allows users to share their private resources (e.g. photos, videos, contact lists) stored on one site with another site without having to hand out their credentials, typically username and password. Google Contact Data [...]]]></description>
				<content:encoded><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/oauth-gmail-logo-420x420.jpg" class="attachment-medium wp-post-image" alt="oauth-gmail-logo" /></p><p>First, let me introduce what Contacts Data API and OAuth is.</p>
<h3>OAuth</h3>
<p>OAuth (Open Authorization) is an open standard for authorization. It allows users to share their private resources (e.g. photos, videos, contact lists) stored on one site with another site without having to hand out their credentials, typically username and password.</p>
<h3>Google Contact Data APIs</h3>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/oauth-gmail-logo.jpg"><img class="alignright size-thumbnail wp-image-52" title="oauth-gmail-logo" src="http://25labs.com/wp-content/uploads/2011/09/oauth-gmail-logo-151x151.jpg" alt="" width="151" height="151" /></a>The Contacts Data API allows client applications to view and update a user&#8217;s contacts. Contacts are stored in the user&#8217;s Google Account; most Google services have access to the contact list.</p>
<p>You can easily find many source codes for importing Gmail contacts by Googling. But most of them use outdated Google Contact Data API or OAuth. By using the latest APIs we can easily import the contacts with fewer lines of code and is much more efficient than the old version. OAuth is in its second generation today. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices. OAuth 2.0 is not backward compatible with OAuth 1.0. Using the older APIs you couldn&#8217;t retrieve the contacts in local host. That is, it was difficult to modify or edit the code for the website as the code had to be uploaded again and again to the host. But with the help of new API you can try and edit the code in local host and it works efficiently.</p>
<p>In this tutorial we will be using OAuth 2.0 and Google Contacts Data API.</p>
<p>You can refer more about them at the links below.</p>
<p><a href="http://code.google.com/apis/accounts/docs/OAuth2.html">http://code.google.com/apis/accounts/docs/OAuth2.html</a></p>
<p><a href="http://code.google.com/apis/contacts/">http://code.google.com/apis/contacts/</a></p>
<p><center><a href="http://25labs.com/demo/import-gmail-contacts/" target="_blank"><img style="margin-right: 10px; margin-bottom: 10px;" src="http://25labs.com/images/view-demo.png" alt="" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px; margin-bottom: 10px;" src="http://25labs.com/images/download-source.png" alt="" /></a></center>As we had a little introduction about both the APIs, we will head to the Step by Step tutorial to import the contacts.</p>
<h3>Step 1:</h3>
<p>Create file &#8216;oauth.php&#8217; in your web-host. For the example that I have shown, I made a folder &#8216;oauth&#8217; in localhost and created the file &#8216;oauth.php&#8217; in the folder.</p>
<p>Thus, in my case, the URL for the file is http://localhost/oauth/oauth.php</p>
<p>Please note your URL for the file, as you will need it in the later steps.</p>
<p>Now paste the code below into &#8216;oauth.php&#8217; and save the file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;meta name=&quot;robots&quot; content=&quot;noindex&quot; /&gt;
&lt;title&gt;Email address list - Import Gmail or Google contacts&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
	a:link {color:Chocolate;text-decoration: none;}
	a:hover {color:CornflowerBlue;}
	.logo{width:100%;height:110px;border:2px solid black;background-color:#666666;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div class=&quot;logo&quot; &gt;
		&lt;a href=&quot;http://25labs.com/&quot; &gt;
			&lt;img style=&quot;padding-top: 10px;&quot; src=&quot;http://25labs.com/wp-content/themes/TheStyle/images/logo.png&quot;&gt;&lt;/img&gt;
		&lt;/a&gt;
	&lt;/div&gt;
	&lt;br/&gt;
	&lt;div&gt;&lt;b&gt;Visit Tutorial: &lt;/b&gt;&lt;a style=&quot;font-size:17px;&quot; href=&quot;http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/&quot; &gt;Import Gmail or Google contacts using Google Contacts Data API and OAuth 2.0 in PHP&lt;/a&gt;&lt;/div&gt;
	&lt;br/&gt;
	&lt;div style=&quot;padding-left: 50px;&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$client_id</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Your Client ID goes here'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client_secret</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Your Client secret goes here'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$redirect_uri</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Your Redirect URIs goes here'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$max_results</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$auth_code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;code&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> curl_file_get_contents<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$userAgent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//The URL to fetch. This can also be set when initializing a session with curl_init().</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//The number of seconds to wait while trying to connect.	</span>
&nbsp;
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$userAgent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//The contents of the &quot;User-Agent: &quot; header to be used in a HTTP request.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//To follow any &quot;Location: &quot; header that the server sends as part of the HTTP header.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_AUTOREFERER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//To automatically set the Referer: field in requests where it follows a Location: redirect.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//The maximum number of seconds to allow cURL functions to execute.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//To stop cURL from verifying the peer's certificate.</span>
&nbsp;
 <span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$contents</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$fields</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'code'</span><span style="color: #339933;">=&gt;</span>  <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$auth_code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'client_id'</span><span style="color: #339933;">=&gt;</span>  <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'client_secret'</span><span style="color: #339933;">=&gt;</span>  <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client_secret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'redirect_uri'</span><span style="color: #339933;">=&gt;</span>  <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirect_uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'grant_type'</span><span style="color: #339933;">=&gt;</span>  <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'authorization_code'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$post</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'='</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rtrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #0000ff;">'https://accounts.google.com/o/oauth2/token'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_POST<span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_POSTFIELDS<span style="color: #339933;">,</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$accesstoken</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">access_token</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://www.google.com/m8/feeds/contacts/default/full?max-results='</span><span style="color: #339933;">.</span><span style="color: #000088;">$max_results</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;oauth_token='</span><span style="color: #339933;">.</span><span style="color: #000088;">$accesstoken</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xmlresponse</span> <span style="color: #339933;">=</span>  curl_file_get_contents<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlresponse</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Authorization required'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlresponse</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Error '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//At times you get Authorization error from Google.</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;OOPS !! Something went wrong. Please try reloading the page.&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h3&gt;Email Addresses:&lt;/h3&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlresponse</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerXPathNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gd'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://schemas.google.com/g/2005'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//gd:email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">address</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/div&gt;
&lt;/body&gt;&lt;/html&gt;</pre></td></tr></table></div>

<h3>Step 2:</h3>
<p>To use the Google API, you need to register your product at Google. To start the Registration process, head to <a href="http://code.google.com/apis/console">Google API Console</a>.</p>
<p>If you haven&#8217;t created any projects yet, then you will be seeing a page as shown below. Click &#8216;Create Project…&#8217; button.</p>
<div id="attachment_50" class="wp-caption aligncenter" style="width: 372px"><a href="http://25labs.com/wp-content/uploads/2011/09/create-project.jpg"><img class="size-full wp-image-50" title="create-project" src="http://25labs.com/wp-content/uploads/2011/09/create-project.jpg" alt="Create Project" width="362" height="333" /></a><p class="wp-caption-text">Create Project</p></div>
<p>If you have created a project earlier, then you will be taken to an existing project directly. Click on the drop down menu that has the current project&#8217;s name which is located at the top left of the webpage (In my case it is &#8216;API Project&#8217;) and click &#8216;Create…&#8217; in &#8216;Other projects&#8217; tab. Now you will be asked to enter the name of the project. Enter a name as you wish.</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/api-projects-drop-down.jpg"><img class="size-medium wp-image-45  " title="api-projects-drop-down" src="http://25labs.com/wp-content/uploads/2011/09/api-projects-drop-down-420x284.jpg" alt="API Projects drop down" width="420" height="284" /></a><p class="wp-caption-text">API Projects drop down</p></div>
<div id="attachment_44" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/api-drop-down-create.jpg"><img class="size-medium wp-image-44  " title="api-drop-down-create" src="http://25labs.com/wp-content/uploads/2011/09/api-drop-down-create-420x284.jpg" alt="API drop down - Create" width="420" height="284" /></a><p class="wp-caption-text">API drop down - Create</p></div>
<h3>Step 3:</h3>
<p>Click &#8216;API Access&#8217; from the let menu.</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/api-access.jpg"><img class="size-full wp-image-42 " title="api-access" src="http://25labs.com/wp-content/uploads/2011/09/api-access-420x420.jpg" alt="API Access" width="420" height="420" /></a><p class="wp-caption-text">API Access</p></div>
<h3>Step 4:</h3>
<p>Now click on &#8216;Create an OAuth 2.0 client ID…&#8217; button on the page that just opened up.</p>
<div id="attachment_49" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/create-oauth-client-id.jpg"><img class="size-medium wp-image-49 " title="create-oauth-client-id" src="http://25labs.com/wp-content/uploads/2011/09/create-oauth-client-id-420x177.jpg" alt="Create OAuth client ID" width="420" height="177" /></a><p class="wp-caption-text">Create OAuth client ID</p></div>
<h3>Step 5:</h3>
<p>Fill in a name for the project. When a user clicks to retrieve the contacts, this product name will be shown on the conformation page. So please provide a sensible name.</p>
<p>You can optional give a product logo. The maximum allowed size for the logo is 120 x 60 pixels. This logo will also be displayed on the user&#8217;s confirmation page.</p>
<div id="attachment_46" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/create-client-id.jpg"><img class="size-medium wp-image-46 " title="create-client-id" src="http://25labs.com/wp-content/uploads/2011/09/create-client-id-420x307.jpg" alt="Create Client ID" width="420" height="307" /></a><p class="wp-caption-text">Create Client ID</p></div>
<p>After you fill in the details click &#8216;Next&#8217; button.</p>
<h3>Step 6:</h3>
<p>Now you will be taken to Client ID settings page.</p>
<p>Choose &#8216;Web application&#8217; radio button for the Application type.</p>
<p>In &#8216;Your site or hostname&#8217; block, choose &#8216;http://&#8217; or &#8216;https://&#8217; as per your requirement.</p>
<p>Now, enter your domain for the web application. You can also provide &#8216;localhost&#8217;.</p>
<div id="attachment_47" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/create-client-id-3.jpg"><img class="size-medium wp-image-47 " title="create-client-id-3" src="http://25labs.com/wp-content/uploads/2011/09/create-client-id-3-420x329.jpg" alt="Create Client ID" width="420" height="329" /></a><p class="wp-caption-text">Create Client ID</p></div>
<p>Now, click &#8216;more options&#8217; which lies next to &#8216;Your site or hostname&#8217;.</p>
<p>Enter the url that we created in Step 1 as &#8216;Authorized Redirect URIs&#8217;.</p>
<p>You will automatically have your host address as &#8216;Authorized JavaScript Origins&#8217;. You can enter more origins if you wish.</p>
<div id="attachment_48" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/create-client-id-4.jpg"><img class="size-medium wp-image-48 " title="create-client-id-4" src="http://25labs.com/wp-content/uploads/2011/09/create-client-id-4-420x389.jpg" alt="Create OAuth client ID" width="420" height="389" /></a><p class="wp-caption-text">Create OAuth client ID</p></div>
<p>Click &#8216;Create client ID&#8217; button.</p>
<h3>Step 7:</h3>
<p>Now you have registered your product and you can view the API credentials for your web application.</p>
<p>Note down the Client ID, Client secret and Redirect URIs. You will need them in Step 8 and 9.</p>
<div id="attachment_43" class="wp-caption aligncenter" style="width: 430px"><a href="http://25labs.com/wp-content/uploads/2011/09/api-credentials-.jpg"><img class="size-medium wp-image-43 " title="api-credentials" src="http://25labs.com/wp-content/uploads/2011/09/api-credentials--420x287.jpg" alt="API Credentials" width="420" height="287" /></a><p class="wp-caption-text">API Credentials</p></div>
<h3>Step 8:</h3>
<p>Open oauth.php that you created in Step 1.</p>
<p>Replace &#8216;Your Client ID goes here&#8217;, &#8216;Your Client secret goes here&#8217; and &#8216;Your Redirect URIs goes here&#8217; with the Client ID, Client secret and Redirect URIs that you created in Step 7, respectively.</p>
<p>You can optionally change the number next to &#8216;$max_results&#8217;. It specifies the maximum number of email addresses to be retrieved.</p>
<h3>Step 9:</h3>
<p>Create the button or link that the user needs to click to retrieve the contact list and set its href parameter to</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">'https://accounts.google.com/o/oauth2/auth?client_id=your_client_id_goes_here&amp;redirect_uri=your_redirest_urls_goes_here&amp;scope=https://www.google.com/m8/feeds/&amp;response_type=code'</pre></td></tr></table></div>

<p>Replace &#8216;your_client_id_goes_here&#8217; and &#8216;your_redirest_urls_goes_here&#8217; with the Client ID and Redirect URIs that you created in Step 7, respectively.</p>
<p>Or you can optionally copy the code given below, replace &#8216;your_client_id_goes_here&#8217; and &#8216;your_redirest_urls_goes_here&#8217; as mentioned above, and save it as a new file, may be &#8216;index.php&#8217;.</p>
<p>Then save it to your host.</p>
<p>Please make sure that you place this file in a directory that satisfies &#8216;JavaScript origins&#8217; that you specified in Step 6.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;robots&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noindex&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Import Gmail or Google contacts using Google Contacts Data API and OAuth 2.0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
	a:link {color:Chocolate;text-decoration: none;}
	a:hover {color:CornflowerBlue;}
	.logo{width:100%;height:110px;border:2px solid black;background-color:#666666;}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;logo&quot;</span> &gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://25labs.com/&quot;</span> &gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;padding-top: 10px;&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://25labs.com/wp-content/themes/TheStyle/images/logo.png&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">img</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>Visit Tutorial: <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font-size:17px;&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/&quot;</span> &gt;</span>Import Gmail or Google contacts using Google Contacts Data API and OAuth 2.0 in PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;center&quot;</span> &gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span>  <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font-size:25px;font-weight:bold;&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://accounts.google.com/o/oauth2/auth?client_id=your_client_id_goes_here&amp;redirect_uri=your_redirest_urls_goes_here&amp;scope=https://www.google.com/m8/feeds/&amp;response_type=code&quot;</span>&gt;</span>Click here to Import Gmail Contacts<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p>We have now successfully completed the web application to retrieve Gmail or Google contacts.</p>
<h2>Testing the web application:</h2>
<p>Now it&#8217;s the turn to test the application. Please follow the steps mentioned below.</p>
<h3>Step 10:</h3>
<p>Browse to the file that created in Step 9 using your favorite web browser. Click on the button or link that you created to retrieve the contacts.</p>
<p>There is a chance that you get an error similar to the one shown below, especially if you are trying it on localhost.</p>
<p><strong>Fatal error:</strong> Call to undefined function curl_init() in C:\xampp\htdocs\oauth\oauth.php on line 24</p>
<p>If you are among the unlucky ones, please follow the procedure mentioned below to solve the issue.</p>
<p><strong>Solution:</strong></p>
<p>If you are on localhost open:</p>
<p>php/php.ini</p>
<p>php/browscap/php.ini (if existent)</p>
<p>php/php4/php.ini (if existent)</p>
<p>apache/bin/php.ini (if existent)</p>
<p>&nbsp;</p>
<p>If you are on web host, open web host&#8217;s &#8216;php.ini&#8217;</p>
<p>&nbsp;</p>
<p>Search for &#8216;extension=php_curl.dll&#8217;.</p>
<p>If not found add it to &#8216;Dynamic Extensions&#8217; section.</p>
<p>If found, uncomment the statement.</p>
<p>Then restart Apache if on localhost.</p>
<p>Try Step 10 again.</p>
<h3>Step 11:</h3>
<p>You will be taken to a conformation page which will look similar to the one shown below.</p>
<div id="attachment_51" class="wp-caption aligncenter" style="width: 406px"><a href="http://25labs.com/wp-content/uploads/2011/09/import-gmail-contacts.jpg"><img class="size-full wp-image-51" title="import-gmail-contacts" src="http://25labs.com/wp-content/uploads/2011/09/import-gmail-contacts.jpg" alt="Import Gmail Contacts" width="396" height="286" /></a><p class="wp-caption-text">Import Gmail Contacts</p></div>
<p>Click &#8216;Allow Access&#8217; button.</p>
<h3>Step 12:</h3>
<p>If everything went right, you will have a list of email addresses on screen.</p>
<p>Please comment below, if you have any queries or errors.</p>
<p><center><a href="http://25labs.com/demo/import-gmail-contacts/" target="_blank"><img style="margin-right: 10px; margin-bottom: 10px;" src="http://25labs.com/images/view-demo.png" alt="" /></a><a href="http://25labs.com/wp-login.php?redirect_to=http%3A%2F%2F25labs.com%2Ffeed%2F" target="_blank"><img style="margin-left: 10px; margin-bottom: 10px;" src="http://25labs.com/images/download-source.png" alt="" /></a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
		<item>
		<title>Analyzing the Internet Giants based on Traffic</title>
		<link>http://25labs.com/analyzing-the-internet-giants-based-on-traffic/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=analyzing-the-internet-giants-based-on-traffic</link>
		<comments>http://25labs.com/analyzing-the-internet-giants-based-on-traffic/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 21:06:17 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[internet]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=29</guid>
		<description><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/largest-websites-logo-420x420.jpg" class="attachment-medium wp-post-image" alt="Largest Websites" /></p>Month on month DoubleClick Ad Planner by Google releases the list of top 1000 sites. (Google acquired DoubleClick in March 2008). The list can be viewed at Ad Planner Top 1000 As at the time of writing this post, the latest list released, dates to June 2011. The list excludes adult sites, ad networks. The [...]]]></description>
				<content:encoded><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/largest-websites-logo-420x420.jpg" class="attachment-medium wp-post-image" alt="Largest Websites" /></p><p>Month on month <a title="DoubleClick Ad Planner" href="http://www.google.com/adplanner/" target="_blank">DoubleClick Ad Planner</a> by Google releases the list of top 1000 sites. (Google acquired DoubleClick in March 2008). The list can be viewed at <a title="Ad Planner Top 1000" href="http://www.google.com/adplanner/static/top1000/" target="_blank">Ad Planner Top 1000</a></p>
<p>As at the time of writing this post, the latest list released, dates to June 2011. The list excludes adult sites, ad networks.</p>
<p>The highlight of the list is <a title="Facebook" href="http://www.facebook.com/" target="_blank">facebook</a>’s trillion pageviews. It has taken just 7 years for facebook to reach the milestone. <a title="Baidu" href="http://www.baidu.com/" target="_blank">Baidu.com</a> is second to <a title="Facebook" href="http://www.facebook.com/" target="_blank">facebook.com</a> in terms of pageviews, and it’s interesting to note that Baidu is no way near to Facebook. Facebook has almost 10 times the pageviews of Baidu. Baidu is a Chinese search engine and so many of you might not be familiar with it.</p>
<p><strong>Many of the Google sites are also excluded from the list.</strong></p>
<h3>The Top 20 websites with maximum unique users</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>Rank</th>
<th>Site</th>
<th>Category</th>
<th>Unique Visitors (users)</th>
<th>Reach</th>
<th>Pageviews</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>1</td>
<td>facebook.com</td>
<td>Social Networks</td>
<td>87,00,00,000</td>
<td>46.90%</td>
<td>10,00,00,00,00,000</td>
</tr>
<tr class="odd">
<td>2</td>
<td>youtube.com</td>
<td>Online Video</td>
<td>79,00,00,000</td>
<td>42.60%</td>
<td>1,00,00,00,00,000</td>
</tr>
<tr class="even">
<td>3</td>
<td>yahoo.com</td>
<td>Web Portals</td>
<td>59,00,00,000</td>
<td>31.80%</td>
<td>78,00,00,00,000</td>
</tr>
<tr class="odd">
<td>4</td>
<td>live.com</td>
<td>Search Engines</td>
<td>54,00,00,000</td>
<td>29%</td>
<td>59,00,00,00,000</td>
</tr>
<tr class="even">
<td>5</td>
<td>wikipedia.org</td>
<td>Dictionaries &amp; Encyclopedias</td>
<td>46,00,00,000</td>
<td>24.50%</td>
<td>6,40,00,00,000</td>
</tr>
<tr class="odd">
<td>6</td>
<td>msn.com</td>
<td>Web Portals</td>
<td>45,00,00,000</td>
<td>24.20%</td>
<td>18,00,00,00,000</td>
</tr>
<tr class="even">
<td>7</td>
<td>blogspot.com</td>
<td>Blogging Resources &amp; Services</td>
<td>37,00,00,000</td>
<td>19.90%</td>
<td>4,80,00,00,000</td>
</tr>
<tr class="odd">
<td>8</td>
<td>baidu.com</td>
<td>Search Engines</td>
<td>31,00,00,000</td>
<td>16.40%</td>
<td>1,20,00,00,00,000</td>
</tr>
<tr class="even">
<td>9</td>
<td>microsoft.com</td>
<td>Software</td>
<td>28,00,00,000</td>
<td>14.90%</td>
<td>2,50,00,00,000</td>
</tr>
<tr class="odd">
<td>10</td>
<td>qq.com</td>
<td>Web Portals</td>
<td>25,00,00,000</td>
<td>13.60%</td>
<td>44,00,00,00,000</td>
</tr>
<tr class="even">
<td>11</td>
<td>bing.com</td>
<td>Search Engines</td>
<td>23,00,00,000</td>
<td>12.40%</td>
<td>9,60,00,00,000</td>
</tr>
<tr class="odd">
<td>12</td>
<td>ask.com</td>
<td>Search Engines</td>
<td>19,00,00,000</td>
<td>10.20%</td>
<td>1,90,00,00,000</td>
</tr>
<tr class="even">
<td>13</td>
<td>taobao.com</td>
<td>Classifieds</td>
<td>17,00,00,000</td>
<td>9.30%</td>
<td>14,00,00,00,000</td>
</tr>
<tr class="odd">
<td>14</td>
<td>twitter.com</td>
<td>Email &amp; Messaging</td>
<td>16,00,00,000</td>
<td>8.60%</td>
<td>5,90,00,00,000</td>
</tr>
<tr class="even">
<td>15</td>
<td>adobe.com</td>
<td>Multimedia Software</td>
<td>16,00,00,000</td>
<td>8.40%</td>
<td>97,00,00,000</td>
</tr>
<tr class="odd">
<td>16</td>
<td>youku.com</td>
<td>Online Video</td>
<td>16,00,00,000</td>
<td>8.50%</td>
<td>4,10,00,00,000</td>
</tr>
<tr class="even">
<td>17</td>
<td>soso.com</td>
<td>Search Engines</td>
<td>14,00,00,000</td>
<td>7.70%</td>
<td>3,90,00,00,000</td>
</tr>
<tr class="odd">
<td>18</td>
<td>wordpress.com</td>
<td>Blogging Resources &amp; Services</td>
<td>14,00,00,000</td>
<td>7.60%</td>
<td>95,00,00,000</td>
</tr>
<tr class="even">
<td>19</td>
<td>sohu.com</td>
<td>Web Portals</td>
<td>13,00,00,000</td>
<td>6.90%</td>
<td>6,50,00,00,000</td>
</tr>
<tr class="odd">
<td>20</td>
<td>163.com</td>
<td>Web Portals</td>
<td>13,00,00,000</td>
<td>7%</td>
<td>6,50,00,00,000</td>
</tr>
</tbody>
</table>
<h3>Top 10 websites with maximum pageviews</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>Rank</th>
<th>Site</th>
<th>Category</th>
<th>Unique Visitors (users)</th>
<th>Reach</th>
<th>Pageviews</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>1</td>
<td>facebook.com</td>
<td>Social Networks</td>
<td>87,00,00,000</td>
<td>46.90%</td>
<td>10,00,00,00,00,000</td>
</tr>
<tr class="odd">
<td>8</td>
<td>baidu.com</td>
<td>Search Engines</td>
<td>31,00,00,000</td>
<td>16.40%</td>
<td>1,20,00,00,00,000</td>
</tr>
<tr class="even">
<td>2</td>
<td>youtube.com</td>
<td>Online Video</td>
<td>79,00,00,000</td>
<td>42.60%</td>
<td>1,00,00,00,00,000</td>
</tr>
<tr class="odd">
<td>3</td>
<td>yahoo.com</td>
<td>Web Portals</td>
<td>59,00,00,000</td>
<td>31.80%</td>
<td>78,00,00,00,000</td>
</tr>
<tr class="even">
<td>4</td>
<td>live.com</td>
<td>Search Engines</td>
<td>54,00,00,000</td>
<td>29%</td>
<td>59,00,00,00,000</td>
</tr>
<tr class="odd">
<td>87</td>
<td>vkontakte.ru</td>
<td>Social Networks</td>
<td>3,80,00,000</td>
<td>2%</td>
<td>52,00,00,00,000</td>
</tr>
<tr class="even">
<td>43</td>
<td>orkut.com.br</td>
<td>Social Networks</td>
<td>6,10,00,000</td>
<td>3.30%</td>
<td>48,00,00,00,000</td>
</tr>
<tr class="odd">
<td>10</td>
<td>qq.com</td>
<td>Web Portals</td>
<td>25,00,00,000</td>
<td>13.60%</td>
<td>44,00,00,00,000</td>
</tr>
<tr class="even">
<td>28</td>
<td>yahoo.co.jp</td>
<td>Web Portals</td>
<td>8,20,00,000</td>
<td>4.40%</td>
<td>32,00,00,00,000</td>
</tr>
<tr class="odd">
<td>39</td>
<td>craigslist.org</td>
<td>Classifieds</td>
<td>6,60,00,000</td>
<td>3.50%</td>
<td>22,00,00,00,000</td>
</tr>
</tbody>
</table>
<p><a href="http://25labs.com/wp-content/uploads/2011/09/largest-websites-logo.jpg"><img class="size-thumbnail wp-image-37 alignright" title="largest-websites-logo" src="http://25labs.com/wp-content/uploads/2011/09/largest-websites-logo-151x151.jpg" alt="Largest Websites" width="151" height="151" /></a>Another key point found from the list is that, facebook has a whooping 1150 pageviews per visitor. The figure shows how much addictive facebook is.</p>
<p>But facebook is not the site which has the highest pageviews per user. It’s only third on this category. The first and the second are vkontakte.ru and tuenti.com respectively. Both are social networks like facebook. Four of the top five websites with maximum pageviews per user are social networks. It shows how much addicted the new generation is, to such networks.</p>
<h3>Top 10 websites with maximum pageviews / user</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>Rank</th>
<th>Site</th>
<th>Category</th>
<th>Unique Visitors (users)</th>
<th>Pageviews</th>
<th>Pageviews / Visitor</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>87</td>
<td>vkontakte.ru</td>
<td>Social Networks</td>
<td>3,80,00,000</td>
<td>52,00,00,00,000</td>
<td>1368.421053</td>
</tr>
<tr class="odd">
<td>600</td>
<td>tuenti.com</td>
<td>Social Networks</td>
<td>89,00,000</td>
<td>11,00,00,00,000</td>
<td>1235.955056</td>
</tr>
<tr class="even">
<td>1</td>
<td>facebook.com</td>
<td>Social Networks</td>
<td>87,00,00,000</td>
<td>10,00,00,00,00,000</td>
<td>1149.425287</td>
</tr>
<tr class="odd">
<td>43</td>
<td>orkut.com.br</td>
<td>Social Networks</td>
<td>6,10,00,000</td>
<td>48,00,00,00,000</td>
<td>786.8852459</td>
</tr>
<tr class="even">
<td>83</td>
<td>naver.com</td>
<td>Search Engines</td>
<td>3,80,00,000</td>
<td>20,00,00,00,000</td>
<td>526.3157895</td>
</tr>
<tr class="odd">
<td>660</td>
<td>hyves.nl</td>
<td>Social Networks</td>
<td>82,00,000</td>
<td>3,30,00,00,000</td>
<td>402.4390244</td>
</tr>
<tr class="even">
<td>28</td>
<td>yahoo.co.jp</td>
<td>Web Portals</td>
<td>8,20,00,000</td>
<td>32,00,00,00,000</td>
<td>390.2439024</td>
</tr>
<tr class="odd">
<td>8</td>
<td>baidu.com</td>
<td>Search Engines</td>
<td>31,00,00,000</td>
<td>1,20,00,00,00,000</td>
<td>387.0967742</td>
</tr>
<tr class="even">
<td>829</td>
<td>wer-kennt-wen.de</td>
<td>Social Networks</td>
<td>68,00,000</td>
<td>2,50,00,00,000</td>
<td>367.6470588</td>
</tr>
<tr class="odd">
<td>853</td>
<td>seznam.cz</td>
<td>Web Portals</td>
<td>67,00,000</td>
<td>2,30,00,00,000</td>
<td>343.2835821</td>
</tr>
</tbody>
</table>
<h2>Search Engines:</h2>
<p>The top 1000 has 22 search engines. Please note the point that Google, which is the largest of the lot, is excluded from the list.</p>
<div id="attachment_30" class="wp-caption aligncenter" style="width: 290px"><a href="http://25labs.com/wp-content/uploads/2011/09/biggest-search-engines-logo.jpg"><img class="size-full wp-image-30 " title="biggest-search-engines-logo" src="http://25labs.com/wp-content/uploads/2011/09/biggest-search-engines-logo.jpg" alt="Biggest Search Engines" width="280" height="280" /></a><p class="wp-caption-text">Biggest Search Engines</p></div>
<h3>List of search engines</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>Rank</th>
<th>Site</th>
<th>Unique Visitors (users)</th>
<th>Reach</th>
<th>Pageviews</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>4</td>
<td>live.com</td>
<td>54,00,00,000</td>
<td>29%</td>
<td>59,00,00,00,000</td>
</tr>
<tr class="odd">
<td>8</td>
<td>baidu.com</td>
<td>31,00,00,000</td>
<td>16.40%</td>
<td>1,20,00,00,00,000</td>
</tr>
<tr class="even">
<td>11</td>
<td>bing.com</td>
<td>23,00,00,000</td>
<td>12.40%</td>
<td>9,60,00,00,000</td>
</tr>
<tr class="odd">
<td>12</td>
<td>ask.com</td>
<td>19,00,00,000</td>
<td>10.20%</td>
<td>1,90,00,00,000</td>
</tr>
<tr class="even">
<td>17</td>
<td>soso.com</td>
<td>14,00,00,000</td>
<td>7.70%</td>
<td>3,90,00,00,000</td>
</tr>
<tr class="odd">
<td>29</td>
<td>sogou.com</td>
<td>8,10,00,000</td>
<td>4.40%</td>
<td>2,00,00,00,000</td>
</tr>
<tr class="even">
<td>61</td>
<td>mywebsearch.com</td>
<td>5,00,00,000</td>
<td>2.70%</td>
<td>1,00,00,00,000</td>
</tr>
<tr class="odd">
<td>65</td>
<td>yandex.ru</td>
<td>4,60,00,000</td>
<td>2.50%</td>
<td>11,00,00,00,000</td>
</tr>
<tr class="even">
<td>83</td>
<td>naver.com</td>
<td>3,80,00,000</td>
<td>2%</td>
<td>20,00,00,00,000</td>
</tr>
<tr class="odd">
<td>123</td>
<td>discoverbing.com</td>
<td>2,80,00,000</td>
<td>1.50%</td>
<td>9,60,00,000</td>
</tr>
<tr class="even">
<td>168</td>
<td>gougou.com</td>
<td>2,30,00,000</td>
<td>1.20%</td>
<td>49,00,00,000</td>
</tr>
<tr class="odd">
<td>197</td>
<td>peeplo.com</td>
<td>1,90,00,000</td>
<td>1%</td>
<td>7,30,00,000</td>
</tr>
<tr class="even">
<td>248</td>
<td>whitepages.com</td>
<td>1,60,00,000</td>
<td>0.90%</td>
<td>21,00,00,000</td>
</tr>
<tr class="odd">
<td>535</td>
<td>isohunt.com</td>
<td>98,00,000</td>
<td>0.50%</td>
<td>28,00,00,000</td>
</tr>
<tr class="even">
<td>555</td>
<td>pcpop.com</td>
<td>91,00,000</td>
<td>0.50%</td>
<td>11,00,00,000</td>
</tr>
<tr class="odd">
<td>582</td>
<td>115.com</td>
<td>90,00,000</td>
<td>0.50%</td>
<td>8,10,00,000</td>
</tr>
<tr class="even">
<td>608</td>
<td>naver.jp</td>
<td>89,00,000</td>
<td>0.50%</td>
<td>7,90,00,000</td>
</tr>
<tr class="odd">
<td>748</td>
<td>ya.ru</td>
<td>75,00,000</td>
<td>0.40%</td>
<td>8,80,00,000</td>
</tr>
<tr class="even">
<td>757</td>
<td>chinaz.com</td>
<td>74,00,000</td>
<td>0.40%</td>
<td>16,00,00,000</td>
</tr>
<tr class="odd">
<td>816</td>
<td>webcrawler.com</td>
<td>68,00,000</td>
<td>0.40%</td>
<td>3,40,00,000</td>
</tr>
<tr class="even">
<td>885</td>
<td>infospace.com</td>
<td>66,00,000</td>
<td>0.40%</td>
<td>6,10,00,000</td>
</tr>
<tr class="odd">
<td>919</td>
<td>information.com</td>
<td>62,00,000</td>
<td>0.30%</td>
<td>1,90,00,000</td>
</tr>
</tbody>
</table>
<h2>Google v/s Facebook</h2>
<p style="text-align: center;"><a href="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook.jpg"><img class="size-full wp-image-32 aligncenter" title="google-vs-facebook" src="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook.jpg" alt="Google vs Facebook" width="280" height="183" /></a></p>
<p>Since May 2011, there has been a battle between google.com and facebook.com, to occupy the top spot in Alexa ranking. The popularity of facebook has increased tremendously in the past few months. Google.com occupies the top spot in terms of unique users and Facebook.com in terms of pageviews.</p>
<h3>Alexa traffic stats comparison between google.com and facebook.com</h3>
<p>Traffic for past six months is compared in the graph. Blue line indicates google.com and red indicates facebook.com</p>
<div id="attachment_35" class="wp-caption aligncenter" style="width: 407px"><a href="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-rank.jpg"><img class="size-full wp-image-35" title="google-vs-facebook-alexa-rank" src="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-rank.jpg" alt="Google.com vs Facebook.com - Alexa Rank" width="397" height="251" /></a><p class="wp-caption-text">Google.com vs Facebook.com - Alexa Rank</p></div>
<div id="attachment_36" class="wp-caption aligncenter" style="width: 407px"><a href="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-reach.jpg"><img class="size-full wp-image-36" title="google-vs-facebook-alexa-reach" src="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-reach.jpg" alt="Google.com vs Facebook.com - Alexa Reach" width="397" height="251" /></a><p class="wp-caption-text">Google.com vs Facebook.com - Alexa Reach</p></div>
<div id="attachment_33" class="wp-caption aligncenter" style="width: 407px"><a href="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-pageviews.jpg"><img class="size-full wp-image-33" title="google-vs-facebook-alexa-pageviews" src="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-pageviews.jpg" alt="Google.com vs Facebook.com - Alexa Pageviews" width="397" height="251" /></a><p class="wp-caption-text">Google.com vs Facebook.com - Alexa Pageviews</p></div>
<div id="attachment_34" class="wp-caption aligncenter" style="width: 407px"><a href="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-pageviews-per-user.jpg"><img class="size-full wp-image-34" title="google-vs-facebook-alexa-pageviews-per-user" src="http://25labs.com/wp-content/uploads/2011/09/google-vs-facebook-alexa-pageviews-per-user.jpg" alt="Google.com vs Facebook.com - Alexa Pageviews / User" width="397" height="251" /></a><p class="wp-caption-text">Google.com vs Facebook.com - Alexa Pageviews / User</p></div>
<p style="text-align: right;">Courtesy: <a title="Alexa" href="http://alexa.com" target="_blank">Alexa</a></p>
<p>But when I say this, a point to note is that, all these stats are of just google.com and Google search has 185 more domains for different countries and regions.</p>
<h3>The complete list of Google domains</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th colspan="5">Google</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>google.com</td>
<td>google.com.co</td>
<td>google.im</td>
<td>google.com.my</td>
<td>google.so</td>
</tr>
<tr class="odd">
<td>google.ad</td>
<td>google.co.cr</td>
<td>google.co.in</td>
<td>google.co.mz</td>
<td>google.sm</td>
</tr>
<tr class="even">
<td>google.ae</td>
<td>google.com.cu</td>
<td>google.iq</td>
<td>google.com.na</td>
<td>google.st</td>
</tr>
<tr class="odd">
<td>google.com.af</td>
<td>google.cz</td>
<td>google.is</td>
<td>google.com.nf</td>
<td>google.com.sv</td>
</tr>
<tr class="even">
<td>google.com.ag</td>
<td>google.de</td>
<td>google.it</td>
<td>google.com.ng</td>
<td>google.td</td>
</tr>
<tr class="odd">
<td>google.com.ai</td>
<td>google.dj</td>
<td>google.je</td>
<td>google.com.ni</td>
<td>google.tg</td>
</tr>
<tr class="even">
<td>google.am</td>
<td>google.dk</td>
<td>google.com.jm</td>
<td>google.ne</td>
<td>google.co.th</td>
</tr>
<tr class="odd">
<td>google.co.ao</td>
<td>google.dm</td>
<td>google.jo</td>
<td>google.nl</td>
<td>google.com.tj</td>
</tr>
<tr class="even">
<td>google.com.ar</td>
<td>google.com.do</td>
<td>google.co.jp</td>
<td>google.no</td>
<td>google.tk</td>
</tr>
<tr class="odd">
<td>google.as</td>
<td>google.dz</td>
<td>google.co.ke</td>
<td>google.com.np</td>
<td>google.tl</td>
</tr>
<tr class="even">
<td>google.at</td>
<td>google.com.ec</td>
<td>google.com.kh</td>
<td>google.nr</td>
<td>google.tm</td>
</tr>
<tr class="odd">
<td>google.com.au</td>
<td>google.ee</td>
<td>google.ki</td>
<td>google.nu</td>
<td>google.tn</td>
</tr>
<tr class="even">
<td>google.az</td>
<td>google.com.eg</td>
<td>google.kg</td>
<td>google.co.nz</td>
<td>google.to</td>
</tr>
<tr class="odd">
<td>google.ba</td>
<td>google.es</td>
<td>google.co.kr</td>
<td>google.com.om</td>
<td>google.com.tr</td>
</tr>
<tr class="even">
<td>google.com.bd</td>
<td>google.com.et</td>
<td>google.com.kw</td>
<td>google.com.pa</td>
<td>google.tt</td>
</tr>
<tr class="odd">
<td>google.be</td>
<td>google.fi</td>
<td>google.kz</td>
<td>google.com.pe</td>
<td>google.com.tw</td>
</tr>
<tr class="even">
<td>google.bf</td>
<td>google.com.fj</td>
<td>google.la</td>
<td>google.com.ph</td>
<td>google.co.tz</td>
</tr>
<tr class="odd">
<td>google.bg</td>
<td>google.fm</td>
<td>google.com.lb</td>
<td>google.com.pk</td>
<td>google.com.ua</td>
</tr>
<tr class="even">
<td>google.com.bh</td>
<td>google.fr</td>
<td>google.li</td>
<td>google.pl</td>
<td>google.co.ug</td>
</tr>
<tr class="odd">
<td>google.bi</td>
<td>google.ga</td>
<td>google.lk</td>
<td>google.pn</td>
<td>google.co.uk</td>
</tr>
<tr class="even">
<td>google.bj</td>
<td>google.ge</td>
<td>google.co.ls</td>
<td>google.com.pr</td>
<td>google.com.uy</td>
</tr>
<tr class="odd">
<td>google.com.bn</td>
<td>google.gg</td>
<td>google.lt</td>
<td>google.ps</td>
<td>google.co.uz</td>
</tr>
<tr class="even">
<td>google.com.bo</td>
<td>google.com.gh</td>
<td>google.lu</td>
<td>google.pt</td>
<td>google.com.vc</td>
</tr>
<tr class="odd">
<td>google.com.br</td>
<td>google.com.gi</td>
<td>google.lv</td>
<td>google.com.py</td>
<td>google.co.ve</td>
</tr>
<tr class="even">
<td>google.bs</td>
<td>google.gl</td>
<td>google.com.ly</td>
<td>google.com.qa</td>
<td>google.vg</td>
</tr>
<tr class="odd">
<td>google.co.bw</td>
<td>google.gm</td>
<td>google.co.ma</td>
<td>google.ro</td>
<td>google.co.vi</td>
</tr>
<tr class="even">
<td>google.by</td>
<td>google.gp</td>
<td>google.md</td>
<td>google.ru</td>
<td>google.com.vn</td>
</tr>
<tr class="odd">
<td>google.com.bz</td>
<td>google.gr</td>
<td>google.me</td>
<td>google.rw</td>
<td>google.vu</td>
</tr>
<tr class="even">
<td>google.ca</td>
<td>google.com.gt</td>
<td>google.mg</td>
<td>google.com.sa</td>
<td>google.ws</td>
</tr>
<tr class="odd">
<td>google.cd</td>
<td>google.gy</td>
<td>google.mk</td>
<td>google.com.sb</td>
<td>google.rs</td>
</tr>
<tr class="even">
<td>google.cf</td>
<td>google.com.hk</td>
<td>google.ml</td>
<td>google.sc</td>
<td>google.co.za</td>
</tr>
<tr class="odd">
<td>google.cg</td>
<td>google.hn</td>
<td>google.mn</td>
<td>google.se</td>
<td>google.co.zm</td>
</tr>
<tr class="even">
<td>google.ch</td>
<td>google.hr</td>
<td>google.ms</td>
<td>google.com.sg</td>
<td>google.co.zw</td>
</tr>
<tr class="odd">
<td>google.ci</td>
<td>google.ht</td>
<td>google.com.mt</td>
<td>google.sh</td>
<td>google.cat</td>
</tr>
<tr class="even">
<td>google.co.ck</td>
<td>google.hu</td>
<td>google.mu</td>
<td>google.si</td>
<td></td>
</tr>
<tr class="odd">
<td>google.cl</td>
<td>google.co.id</td>
<td>google.mv</td>
<td>google.sk</td>
<td></td>
</tr>
<tr class="even">
<td>google.cm</td>
<td>google.ie</td>
<td>google.mw</td>
<td>google.com.sl</td>
<td></td>
</tr>
<tr class="odd">
<td>google.cn</td>
<td>google.co.il</td>
<td>google.com.mx</td>
<td>google.sn</td>
<td></td>
</tr>
</tbody>
</table>
<h2>Advertising in websites:</h2>
<p>Major revenue for most of the websites, is from advertisements. Of the top 1000 websites 841 has some sort of advertising in it. Websites that doesn’t have advertisements is only 159. Online advertising has gained momentum in the past few years and it has much more un-tapped potential.</p>
<div id="attachment_31" class="wp-caption aligncenter" style="width: 310px"><a href="http://25labs.com/wp-content/uploads/2011/09/biggest-websites-with-no-advrtising.jpg"><img class="size-full wp-image-31" title="biggest-websites-with-no-advrtising" src="http://25labs.com/wp-content/uploads/2011/09/biggest-websites-with-no-advrtising.jpg" alt="Websites with no advertising" width="300" height="235" /></a><p class="wp-caption-text">Websites with no advertising</p></div>
<h3>Top 10 websites that doesn&#8217;t have advertising</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>Rank</th>
<th>Site</th>
<th>Category</th>
<th>Unique Visitors (users)</th>
<th>Reach</th>
<th>Pageviews</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>5</td>
<td>wikipedia.org</td>
<td>Dictionaries &amp; Encyclopedias</td>
<td>46,00,00,000</td>
<td>24.50%</td>
<td>6,40,00,00,000</td>
</tr>
<tr class="odd">
<td>14</td>
<td>twitter.com</td>
<td>Email &amp; Messaging</td>
<td>16,00,00,000</td>
<td>8.60%</td>
<td>5,90,00,00,000</td>
</tr>
<tr class="even">
<td>15</td>
<td>adobe.com</td>
<td>Multimedia Software</td>
<td>16,00,00,000</td>
<td>8.40%</td>
<td>97,00,00,000</td>
</tr>
<tr class="odd">
<td>33</td>
<td>mozilla.com</td>
<td>Internet Clients &amp; Browsers</td>
<td>7,30,00,000</td>
<td>3.90%</td>
<td>44,00,00,000</td>
</tr>
<tr class="even">
<td>39</td>
<td>craigslist.org</td>
<td>Classifieds</td>
<td>6,60,00,000</td>
<td>3.50%</td>
<td>22,00,00,00,000</td>
</tr>
<tr class="odd">
<td>41</td>
<td>orkut.com</td>
<td>Social Networks</td>
<td>6,60,00,000</td>
<td>3.60%</td>
<td>4,00,00,00,000</td>
</tr>
<tr class="even">
<td>43</td>
<td>orkut.com.br</td>
<td>Social Networks</td>
<td>6,10,00,000</td>
<td>3.30%</td>
<td>48,00,00,00,000</td>
</tr>
<tr class="odd">
<td>62</td>
<td>17kuxun.com</td>
<td></td>
<td>5,00,00,000</td>
<td>2.70%</td>
<td>19,00,00,000</td>
</tr>
<tr class="even">
<td>72</td>
<td>camzap.com</td>
<td>Webcams &amp; Virtual Tours</td>
<td>4,20,00,000</td>
<td>2.20%</td>
<td>19,00,00,000</td>
</tr>
<tr class="odd">
<td>79</td>
<td>360.cn</td>
<td>Antivirus &amp; Malware</td>
<td>4,10,00,000</td>
<td>2.20%</td>
<td>97,00,00,000</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/analyzing-the-internet-giants-based-on-traffic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternative for file_get_contents() using cURL</title>
		<link>http://25labs.com/alternative-for-file_get_contents-using-curl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=alternative-for-file_get_contents-using-curl</link>
		<comments>http://25labs.com/alternative-for-file_get_contents-using-curl/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 20:38:03 +0000</pubDate>
		<dc:creator>Tebe Tensing</dc:creator>
				<category><![CDATA[Web Designing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web designing]]></category>

		<guid isPermaLink="false">http://25labs.com/?p=24</guid>
		<description><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/curl-php-420x420.jpg" class="attachment-medium wp-post-image" alt="curl-php" /></p>file_get_contents() is the easiest and most widely used function to get the contents of a file. Just this simple function call could get the contents of a file for you. But if you wish to work on remote files, then you need to enable ‘allow_url_fopen’ in your ‘php.ini’ settings. But enabling ‘allow_url_fopen’ is a risk, [...]]]></description>
				<content:encoded><![CDATA[<p><img width="420" height="420" src="http://25labs.com/wp-content/uploads/2011/09/curl-php-420x420.jpg" class="attachment-medium wp-post-image" alt="curl-php" /></p><p>file_get_contents() is the easiest and most widely used function to get the contents of a file. Just this simple function call could get the contents of a file for you. But if you wish to work on remote files, then you need to enable ‘allow_url_fopen’ in your ‘php.ini’ settings. But enabling ‘allow_url_fopen’ is a risk, as it has various security loop holes. So, it’s always good to disable it and look for an alternative to get the contents of a file.</p>
<p>Some hosts disable the function file_get_contents() for remote files. In that case you are forced to look for an alternative. In some cases file_get_contents() returns NULL or an empty string for perfectly right URLs.</p>
<p>Because of all this, a code using file_get_contents() which works perfectly on one machine or host may not work on another. So it’s always better to use an alternative to get the job done, even if file_get_contents() is working on your system.</p>
<p>The function below, which uses cURL, fulfils our objective. It is much efficient than file_get_contents(). It can be used for remote files also.</p>
<h3>Function:</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> curl_file_get_contents<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$userAgent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The URL to fetch. This can also be set when initializing a session with curl_init().</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span>CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The number of seconds to wait while trying to connect.	</span>
&nbsp;
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$userAgent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The contents of the &quot;User-Agent: &quot; header to be used in a HTTP request.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FAILONERROR<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//To fail silently if the HTTP code returned is greater than or equal to 400.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//To follow any &quot;Location: &quot; header that the server sends as part of the HTTP header.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_AUTOREFERER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//To automatically set the Referer: field in requests where it follows a Location: redirect.</span>
 <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//The maximum number of seconds to allow cURL functions to execute.	</span>
&nbsp;
 <span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$contents</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Lines 10 to 14 may not be required in all cases. But I have included them to be on the safe side.</p>
<h3>Usage:</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$file_content</span> <span style="color: #339933;">=</span> curl_file_get_contents<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://25labs.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Another advantage of this cURL method is that, it is faster than traditional file_get_contents(). I just tried to verify the same using below mentioned timer class. The timer class can be used to benchmark how long queries, functions, and entire pages are taking to complete.</p>
<h3>Function:</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> timer
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$start</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$pause_time</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> timer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Start the timer</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span>	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Start the timer</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pause_time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> pause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Pause the timer</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pause_time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> unpause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Unpause the timer</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">start</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pause_time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pause_time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$decimals</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Get the current timer value</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$decimals</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> get_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #666666; font-style: italic;">//Format the time in seconds</span>
		<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usec</span><span style="color: #339933;">,</span><span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$usec</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Usage:</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$timer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> timer<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Constructor starts the timer, so no need to do it ourselves</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* ... mysql query ...*/</span>
&nbsp;
<span style="color: #000088;">$query_time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* ... page processing ...*/</span>
&nbsp;
<span style="color: #000088;">$processing_time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p style="text-align: right;">Courtesy: <a title="PHP Timer Benchmark" href="http://davidwalsh.name/php-timer-benchmark/" target="_blank">http://davidwalsh.name/php-timer-benchmark/</a></p>
<p>The results of my tests were remarkable. The cURL method proved to be 2-3 times faster. The average increase in speed for downloading <a title="Google" href="http://www.google.com" target="_blank">www.google.com</a> was about 260% and for <a title="25 labs" href="http://25labs.com" target="_blank">25labs.com</a> it was about 200%. The complete test results are shown below.</p>
<h3>Google.com</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>cURL<br />
[seconds]</th>
<th>file_get_contents()<br />
[seconds]</th>
<th>Difference<br />
[seconds]</th>
<th>Increase in speed<br />
[percentage]</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>0.888551</td>
<td>4.50224614</td>
<td>3.61369514</td>
<td>406.6952983</td>
</tr>
<tr class="odd">
<td>0.48516011</td>
<td>1.05094695</td>
<td>0.56578684</td>
<td>116.6185819</td>
</tr>
<tr class="even">
<td>1.12226319</td>
<td>2.02632523</td>
<td>0.90406204</td>
<td>80.55704295</td>
</tr>
<tr class="odd">
<td>0.48129988</td>
<td>1.03340602</td>
<td>0.55210614</td>
<td>114.7114643</td>
</tr>
<tr class="even">
<td>1.47997999</td>
<td>4.94326782</td>
<td>3.46328783</td>
<td>234.0090983</td>
</tr>
<tr class="odd">
<td>1.88002896</td>
<td>5.40903306</td>
<td>3.5290041</td>
<td>187.7100925</td>
</tr>
<tr class="even">
<td>0.45613194</td>
<td>2.84422398</td>
<td>2.38809204</td>
<td>523.5529088</td>
</tr>
<tr class="odd">
<td>0.49854517</td>
<td>0.97496605</td>
<td>0.47642088</td>
<td>95.5622296</td>
</tr>
<tr class="even">
<td>0.46968794</td>
<td>0.97128391</td>
<td>0.50159597</td>
<td>106.7934531</td>
</tr>
<tr class="odd">
<td>0.49630809</td>
<td>4.06055999</td>
<td>3.5642519</td>
<td>718.1530932</td>
</tr>
<tr class="even" style="font-weight: bold;">
<td colspan="3">Average increase in speed [percentage]</td>
<td>258.4363263</td>
</tr>
</tbody>
</table>
<h3>25labs.com</h3>
<table class="wp-table-reloaded">
<thead>
<tr class="odd">
<th>cURL<br />
[seconds]</th>
<th>file_get_contents()<br />
[seconds]</th>
<th>Difference<br />
[seconds]</th>
<th>Increase in speed<br />
[percentage]</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td>4.55120611</td>
<td>9.20000005</td>
<td>4.64879394</td>
<td>102.1442191</td>
</tr>
<tr class="odd">
<td>2.00834012</td>
<td>5.72773004</td>
<td>3.71938992</td>
<td>185.1972125</td>
</tr>
<tr class="even">
<td>1.92637897</td>
<td>4.68373394</td>
<td>2.75735497</td>
<td>143.1366835</td>
</tr>
<tr class="odd">
<td>1.42010713</td>
<td>4.20022202</td>
<td>2.78011489</td>
<td>195.7679693</td>
</tr>
<tr class="even">
<td>1.75494885</td>
<td>6.52712488</td>
<td>4.77217603</td>
<td>271.9267875</td>
</tr>
<tr class="odd">
<td>1.684129</td>
<td>8.10363817</td>
<td>6.41950917</td>
<td>381.1768083</td>
</tr>
<tr class="even">
<td>1.66302896</td>
<td>5.54452515</td>
<td>3.88149619</td>
<td>233.3991941</td>
</tr>
<tr class="odd">
<td>2.46324897</td>
<td>5.85300899</td>
<td>3.38976002</td>
<td>137.6133741</td>
</tr>
<tr class="even">
<td>1.62948298</td>
<td>4.60624599</td>
<td>2.97676301</td>
<td>182.6814423</td>
</tr>
<tr class="odd">
<td>1.99712992</td>
<td>5.29414988</td>
<td>3.29701996</td>
<td>165.0879057</td>
</tr>
<tr class="even" style="font-weight: bold;">
<td colspan="3">Average increase in speed [percentage]</td>
<td>199.8131596</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://25labs.com/alternative-for-file_get_contents-using-curl/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 12.942 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-24 21:37:22 -->
