Я пытаюсь получить мои контакты hotmail из API контактов Windows Live. Я последовал за учебником и загрузил код php и html. Хотя он должен работать, и он дает мне ключ назад, он ничего не покажет.Windows Live Contact 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';
?>