Yahoo OAuth to Import Contacts

Posted: March 8, 2014 in Must Watch, Php
Tags:

Courtesy:-http://codeitall.wordpress.com/2012/01/21/yahoo-oauth-to-import-contacts/

This is similar to Gmail OAuth.

First get the API KEY from Yahoo.

Then set the application’s access on the proceding page. Like set Messanger Access Contact, then access the data for Contacts.

Get the App ID, Consumer Key, and Consumer Secret.

Then start coding the below lines.

config.php

<?php $app_id = '[Enter the Application ID]'; $consumer_key = '[Enter the Consumer Key]'; $consumer_secret= '[Enter the Consumer Secret]'; $connected_path = 'Connected.php'; $re_url = "[Enter the path to Connected.php]/Connected.php"; ?>

ReadyGetConnection.php

<?php include_once 'config.php'; ?> <a href="<?=$connected_path?>">Connect me with Yahoo</a>

Connected.php

<? include_once 'config.php'; require_once ('Yahoo.inc'); $session = YahooSession::requireSession($consumer_key,$consumer_secret,$app_id); if (is_object($session)) { $user = $session->getSessionedUser(); $profile = $user->getProfile(); $name = $profile->nickname; // Getting user name $guid = $profile->guid; // Getting Yahoo ID $contacts=$user->getContacts()->contacts; echo "Hi! ".$name."<br />"; for ($i=0,$k=0;$i<count($contacts->contact);$i++) { for($j=0;$j<count($contacts->contact[$i]->fields);$j++) { $url_data = $contacts->contact[$i]->fields[$j]->uri; $url_pie=explode("/user/", $url_data); $url_end=substr($url_pie[1], stripos($url_pie[1], "/")+1); $data=explode("/", $url_end); if ($data[2]==="email") { $email_fr[$k]=$user->getDatafrom($url_end)->email->value; $k++; } } } echo "You have ".$k." contacts.<br />"; for($i=0;$i<$k;$i++) echo ($i+1).": ".$email_fr[$i]."<br />"; } else { header("Location :".$re_url); }

Yahoo.inc can be downloaded here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s