Sunday, June 30, 2013

Yahoo Oauth Login Connect Using PHP

Little Description
1. If user want to login with his yahoo account he is redirected to yahoo login page from our website for authentication.
2. After successful login yahoo issues user data along with his GUID (Globally Unique Identifier) to our website.
3. We are identifying a user using his GUID in our database. In third step we need to check our database for existence of GUID if it is present the user is old user and display his account. If GUID is not present insert a new record and allot new privileges for him by creating a new account.
4. Display user account with his data.

In order to start working with Yahoo SDK you need to register a web application and get the Application ID, Consumer keys.

1. Creating a new Application
a) Register a new application
b) Get the Application ID, Consumer Key and Consumer Secret. Setup permission level to your application as much as you need.































<?php
require 'lib/Yahoo.inc';
session_start();
/* Place Yoru Consumer Key here */ 
define('OAUTH_CONSUMER_KEY', 'your_consumer_key'); 
 
/* Place your Consumer Secret */ 
define('OAUTH_CONSUMER_SECRET', 'your_consumer_secret'); 
 
/* Place your Application Id here */ 
define('OAUTH_APP_ID', 'your_app_id');
 
/* Your return url which you provide when create application */ 
define("YAHOO_APPLICATION_URL", "http://allinone.com/yahoo.com");
 
$session = YahooSession::requireSession(
    OAUTH_CONSUMER_KEY, 
    OAUTH_CONSUMER_SECRET, 
    OAUTH_APP_ID,
    YAHOO_APPLICATION_URL
);
 
if (is_object($session))  {
    $user = $session->getSessionedUser();
    $profile = $user->getProfile();
    $status = $user->getPresence(); // Fetch the status for the current user.  
    $name = $profile->nickname; // Getting user name
    $guid = $profile->guid; // Getting Yahoo ID 
     
    $start = 0; $count = 100; $total = 0
    $connections = $user->getConnections($start, $count, $total);
 
    $updates = $user->getUpdates();  //Fetch the updates for the current user.     
    //Fetch the updates for the connections of the current user.  
    $connectionUpdates = $user->getConnectionUpdates();
}
 
/* POSTING USER ACTIVITIES */

  1.    $user = $session->getSessionedUser();  
  2.   
  3.    // set the status for the user  
  4.    $status = "is hacking";  
  5.    $user->setStatus($status);  
  6.   
  7.    // store the update data  
  8.    $title = "wrote a new blog post.";  
  9.    $description = "Lorem ipsum dolor sit amet...";  
  10.    $link = "http://pritomkumarb.blogspot.com/blog/my-awesome-blog-post";  
  11.   
  12.    // create an unique hash of the update data using md5  
  13.    $suid = md5($title.$description.$link.time());  
  14.   
  15.    // insert the update...  
  16.    $user->insertUpdate($suid, $title, $link, $description);
   
 

USING YQL

Using Yahoo! Query Language (YQL) in your applications lets you query for data across many other Yahoo! APIs and other data sources across the internet. Learn more about Yahoo! Query Language (YQL) here.
The sample query below gets the user's location and queries the GeoPlanet API in order to return structured place data.

  1.    $query = sprintf("select * from geo.places where text='ballard';");  
  2.    $response = $session->query($query);  
  3.   
  4.    print_r($response);

 
?>
Download Library File

No comments:

Post a Comment