Jun 18, 2013

How to fetch contacts from yahoo account

It is been a tough job now-a-days to fetch contact details from yahoo account. I was struggling for days to fetch the emails from my own yahoo account using yahoo api, then after several days finally got the success. So as i was struggling for long, may be possible there are people like me also finding it hard to get emails, so i thought of sharing the whole process here.

Simple steps to fetch contact details

1. Create a yahoo application by visiting http://developer.yahoo.com. Get application ID, its secret key and consumer key. Make sure while creating your application, you provide the correct domain name on which you will use this module.

2. Download the complete working module for this from our git repository. Create a folder named Yahoo, put the repository content in this folder, then put folder Yahoo in your root directory.

Easy so far.

3. Update your application's ID, its secret key, domain name which you specified at the time of creation of your yahoo app, and consumer key in common.inc.php file under email folder.

Done ?

4. Run http://Your_Domain/Yahoo/email/simpleauth.php in your browser.

And we are done, emails of your contacts are on your screen.
If you need complete profile, then uncomment "print_r($profile);" in file simpleauth.php. And fetch whatever you want from this array.

Hope this helped. Thanks. Any query is most welcomed.

May 7, 2013

Facebook Graph API Access Tokens

When a developer start using Facebook Graph API  first thing that comes to his mind is authentication by Facebook. Most popular word used is Facebook documentation for this is access token.

What is access token?
Why i need it?
What is its purpose?
These are the common question comes to developers mind when he/she heard about this world.

Facebook implementation of the OAuth 2.0 involves three different steps:-1. User authentication, 2. App authorization and 3. App authentication. User authentication ensures that the user is who they say they are. App authorization ensures that the user knows exactly what data and capabilities they are providing to your app. App authentication ensures that the user is giving their information to your app and not someone else. Once these steps are complete, your app is issued an user access token that you enables you to access the user's information and take actions on their behalf.

How to get access token by PHP SDK ?
$facebook = new Facebook(array(
            'appId' => APP_ID,
            'secret' => APP_SECRET,
How to get extend it ? PHP sdk 3.2.2 provides inbuilt method to extend access token to 60 days validity. The function name is setExtendedAccessToken, and it destroys the session afterwards, to remove the risk of having two active sessions. Also, the function no longer actually returns the token, but instead stores it within the persistant data. You can therefore get the new access token with the public function getAccessToken afterwards.  Grab the new SDK from official Facebook PHP SDK github page to make sure you're up to date. 
Access token Debugging
Debug online https://developers.facebook.com/tools/debug Debug by api
GET /debug_token?


How to handle expired tokens

Official documentation have some good resources to explain this.

More about tokens


May 1, 2013

Run FQL queries with Facebook PHP SDK


So the other day while building a Facebook application, I needed to get some information that I just couldn’t find any way to get other than through the use of FQL .

Getting Started

So if you’re looking to run a FQL query and you’re using the new PHP SDK for the Graph API, your code should look something like this:
$facebook = new Facebook(array(
       'appId'  => 'YOUR_API_KEY',
       'secret' => 'YOUR_API_SECRET',
       'cookie' => true,

// get extended acces token with 60 days validity
$accessToken = $facebook->getAccessToken();

 $fql = "Your query";

 $response = $facebook->api(array(
     'method' => 'fql.query',
     'query' =>$fql,


$param  =   array(
      'method'    => 'fql.query',
      'access_token' => $accessToken,
      'query'     => $fql,
      'callback'  => ''
$response   =   $facebook->api($param);

Mar 8, 2013

Wordpress Menus – Add a register login / logout link


While building a WordPress Application, I have to add register, login/logout link to my menu and i gone through a very nice post. But what if you have multiple menus in your theme ? I gone through this situation and want to share my code.
Getting Started
Create a menu without theme location and call it wherever you want in your in your theme.

and put this code in theme functions functions.php
function add_login_logout_link($items, $args) {
    if (empty($args->theme_location)) {
        if (is_user_logged_in()) {
            $newitems = '';
            $newitems .= '
  • Logout
  • '; } else { $newitems = ''; $newitems .= '
  • Register
  • '; $newitems .= '
  • Login
  • '; } return $newitems; } else { return $items; } } add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Disqus for codetohack