2014-01-22 27 views

回答

0

這裏是得到的Hotmail用戶配置文件的詳細代碼

<?php 
$client_id  = 'Your client id'; 
$client_secret = 'client secret key'; 
$redirect_uri = 'redirect url'; 
$auth_code  = $_GET["code"]; 

// get contacts 
$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; 

$my_url = "https://apis.live.net/v5.0/me?access_token=".$accesstoken; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_URL,$my_url); 
$myres=curl_exec($ch); 
curl_close($ch); 

$myxml = json_decode($myres, true); 

$myemailid = $myxml['emails']['account']; 
$username = $myxml['name']; 
?> 
相關問題