[英]Windows Live Contact API The requested url was not found on this server?
我正在嘗試從Windows Live Contacts API獲取我的hotmail聯系人。 我按照教程學習並下載了php和html代碼。 即使它可以正常工作,並且給了我一把鑰匙,它也不會顯示任何東西。
當我嘗試獲取聯系人時,它首先會征得我的許可,此后,我將自動返回到自己的頁面,即當我遇到錯誤時。
錯誤:找不到
在此服務器上找不到請求的URL /result.php?code=xxxxxx-xxxxx-xxxxxxxx-xxxx。
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';
?>
在用戶同意后,WindowsLive無法正確重定向到您的$redirect_uri
:請驗證該值是否正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.