0
我想從Windows Live Contacts API獲取我的Hotmail聯繫人。我遵循教程並下載了php和html代碼。儘管它應該能夠工作,並且它給了我一把鑰匙,它不會顯示任何東西。Windows Live聯繫人API在此服務器上找不到請求的URL?
當我嘗試獲取聯繫人時,它首先詢問我的許可,之後我會自動返回到我自己的頁面,並且當我收到錯誤時。
Error: Not Found
The requested URL /result.php?code=xxxxxx-xxxxx-xxxxxxxx-xxxx was not found on this server.
的index.php
<?php
include('config.php');
$url = '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;
?>
<html>
<body link="#0C6182" vlink="#0C6182" alink="#0C6182">
<a href="<?php print $url; ?>" style="text-decoration: none"> Invite Friends From Hotmail</a>
</body>
</html>
Result.php
<?php
session_start();
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;
}
?>
<html>
<body >
<div align="center">
<table>
<tr>
<td>
<?php
//setting parameters
include('config.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;
$xmlresponse = curl_file_get_contents($url);
$xml = json_decode($xmlresponse, true);
$contacts_email = "";
$count = 0;
foreach ($xml['data'] as $title) {
$count++;
echo $count.". ".$title['emails']['personal'] . "<br><br>";
}
?>
</td>
</tr>
</table>
</div>
</body>
</html>
的config.php
<?php
$client_id = 'xxxxxxxx';
$client_secret = 'xxxxxx-xxxxxxxxxx';
$redirect_uri = 'xxxxxxxxx';
?>