Outlook REST API不返回它应该的所有数据

时间:2016-03-10 10:27:18

标签: php rest outlook


情况:
我正在尝试返回我的Hotmail通讯录的信息。我正在使用我想要和需要的所有范围,请参阅此处(Index.php:$ urls_):wl.signin+wl.basic+wl.emails+wl.contacts_emails+wl.birthday+wl.postal_addresses+wl.phone_numbers

但唯一真正有效的是wl.signin+wl.basic+wl.emails+wl.contacts_emails。那些不工作的东西不会返回任何东西,甚至不会返回NULL。

问题:
如何让api返回联系人邮政地址,电话号码和生日,而不只是姓名和电子邮件?

附加的:

  • 我用来获取联系人的帐户是一个测试帐户 我手动添加的一个联系人。
  • 是不是因为我没有成为联系人的朋友?
  • 现在我正在使用一个简单的echo看看是什么 $xmlresponse包含。

这就是api的回报:

{
   "data": [
      {
         "id": "contact.eefb1331000000000000000000000000", 
         "first_name": "Mike", 
         "last_name": "Lammers", 
         "name": "Mike Lammers", 
         "is_friend": false, 
         "is_favorite": false, 
         "user_id": null, 
         "email_hashes": [
            "f981031f06db7ae6f6dabdd368785eece037ba13f4b3f99ff702d950fa1561e9", 
            "f047784aa8b6bfb8895a06739741f2733b80371e8e88a10b33dfdee5214c7a7b", 
            "b1edf3ecd7c0669a01a6539b965e88aebe1d20ceef578f8699b8cb4355e02626"
         ], 
         "updated_time": "2016-03-10T08:31:48+0000", 
         "emails": {
            "preferred": "persoonlijk@gmail.com", 
            "account": null, 
            "personal": "persoonlijk@gmail.com", 
            "business": "werk@gmail.com", 
            "other": "overig@gmail.com"
         }
      }
   ], 
   "paging": {

   }
}

OAuth的hotmail.php

<?php

//function for parsing the curl request
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;
}
$client_id = 'xxxxx';
$client_secret = 'xxxxxxx';
$redirect_uri = 'http://localhost:11080/oauth-hotmail.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);
echo $contents ;

$response =  json_decode($result);
$accesstoken = $response->access_token;
//$accesstoken = $_SESSION['accesstoken'] ;//= $_GET['access_token'];
$url = 'https://apis.live.net/v5.0/me/contacts?access_token='.$accesstoken.'&limit=500';
$xmlresponse =  curl_file_get_contents($url);
$contacts = json_decode($xmlresponse, true);
$return = array();

$hotmail_contacts = $return;
$hotmail_json = json_encode($return);

echo '<br><br><pre>';
echo $xmlresponse;
echo '</pre><br><br>';

?>

的index.php

<?php
session_start();
$client_id = 'xxxx';
$client_secret = 'xxxx';
$redirect_uri = 'http://localhost:11080/oauth-hotmail.php';

$urls_ = 'https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin+wl.basic+wl.emails+wl.contacts_emails+wl.birthday+wl.postal_addresses+wl.phone_numbers
&response_type=code&redirect_uri='.$redirect_uri;

?>
<!DOCTYPE>
<html>

<body>
<?php echo '<a href="'.$urls_.'">Contact From MSN</a>';?>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

将所有不起作用的范围更改为wl.contacts_ .....见下文

范围= wl.signin + wl.basic + wl.emails + wl.contacts_emails + wl.contacts_birthday + wl.contacts_postal_addresses + wl.contacts_phone_numbers。

这是因为您使用的范围只能访问您自己的详细信息,而不能访问联系人列表中的人员。