Courtesy:-http://www.walkswithme.net/hotmail-contact-list-reader-api-in-php-msn-oauth
Hotmail Contact list reader API or MSN Oauth API is used for importing the contact list from MSN account .Now these days it is very important to get the contact list of MSN account for several web applications. How they simply get those Hotmail contact list ? with no other security issue the answer is simple they are using MSN Oauth for reading the Hotmail contact list.
First you have sign up with the MSN account for submitting your application on the Microsoft Server.It take only few seconds for registering your application with MSN Check here
Image may be NSFW.
Clik here to view.
Register with MSN Oauth
Next you have to provide the return url on the page and get both client id and secret key.
Image may be NSFW.
Clik here to view.
Hotmail Contact list reader api with MSN Oauth
When you signup with MSN then you will get one Client id and Secret key after that you have to create a User interface for the Hotmail contact list reader application create a file with hotmailimport.php and have the following codes.
<?php
//***************************************MSN START********************************
$client_id = 'CLIENT_ID';
$client_secret = 'SECRET_KEY';
$redirect_uri = 'http://www.yourdomain.com/oauth-hotmail.php';
$urls_ = 'https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails&response_type=code&redirect_uri='.$redirect_uri;
$msn_link = '<a href="'.$urls_.'" >MSN Contacts</a>';
echo $msn_link;
//***************************************MSN ENDS********************************
?>
After creating above file you have to create a call back file like the oauth-hotmail.php and have the following codes.
<?php
//function for parsing the curl request
function curl_file_get_contents($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$client_id = 'CLIENT_ID';
$client_secret = 'SECRET_KEY';
$redirect_uri = 'http://www.yourdomain.com/oauth-hotmail.php';
$auth_code = $_GET["code"];
$fields=array(
'code'=> urlencode($auth_code),
'client_id'=> urlencode($client_id),
'client_secret'=> urlencode($client_secret),
'redirect_uri'=> urlencode($redirect_uri),
'grant_type'=> urlencode('authorization_code')
);
$post = '';
foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
$post = rtrim($post,'&');
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://login.live.com/oauth20_token.srf');
curl_setopt($curl,CURLOPT_POST,5);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
$accesstoken = $response->access_token;
$url = 'https://apis.live.net/v5.0/me/contacts?access_token='.$accesstoken.'&limit=100';
$xmlresponse = curl_file_get_contents($url);
$xml = json_decode($xmlresponse, true);
$msn_email = "";
foreach($xml['data'] as $emails)
{
// echo $emails['name'];
$email_ids = implode(",",array_unique($emails['emails'])); //will get more email primary,sec etc with comma separate
$msn_email .= "<div><span>".$emails['name']."</span> <span>". rtrim($email_ids,",")."</span></div>";
}
echo $msn_email;
?>
The above result contains decrypted email id from Hotmail Contacts ,By normally they don’t provide decrypted email for that we have to pass additional permission for this actions like
scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails
in the Hotmail Contact list reader MSN Oauth Api call https://login.live.com/oauth20_authorize.srf?client_id….
Image may be NSFW.
Clik here to view. Thanks for reading Image may be NSFW.
Clik here to view. Image may be NSFW.
Clik here to view. Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Clik here to view.
