0

我正在尝试从 Windows Live Contacts API 获取我的 hotmail 联系人。我按照教程下载了 php 和 html 代码。尽管它应该可以工作并且它给了我一个钥匙,但它不会显示任何东西。

当我尝试获取联系人时,它首先征求我的许可,之后我会自动返回我自己的页面,这就是我收到错误的时候。

错误:未找到
在此服务器上未找到请求的 URL /result.php?code=xxxxxx-xxxxx-xxxxxxxx-xxxx。

索引.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>

结果.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>";

                }

                ?>

                &nbsp;</td>
        </tr>
    </table>
</div>
</body>
</html>

配置文件

<?php
$client_id = 'xxxxxxxx';
$client_secret = 'xxxxxx-xxxxxxxxxx';
$redirect_uri = 'xxxxxxxxx';
?>
4

1 回答 1

0

在用户同意后,WindowsLive 无法正确重定向到您的$redirect_uri: 请验证该值是否正确。

于 2016-02-27T09:49:18.820 回答