繁体   English   中英

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

[英]Outlook REST API not returning all the data it should


情况:
我试图返回我的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>

将所有无效的作用域更改为wl.contacts_ .....参见下文

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM