我一直在尝试将Outlook 365中的所有联系人导入另一个数据库。获取所有姓名,电子邮件,地址等都没有问题。
但是,当我想获取位于Outlook 365中第二页联系人页面上的Notes时,它们会显示为空。
我正在使用PHP代码,使用此URL调用API:
https://outlook.office.com/api/v2.0/Me/Contacts
没有特定参数。所有登录,令牌等部分都得到妥善处理和正常运作。
以下是我使用print_r调用时当前收到的数组示例:
数组([Id] => ... [CreatedDateTime] => ... [LastModifiedDateTime] => ... [ChangeKey] => ... [分类] =>数组([0] => ...) [ParentFolderId] => ... [生日] => [FileAs] => ... [DisplayName] => ... [GivenName] => ... [姓名缩写] => [MiddleName] => [NickName] => ... [姓氏] => ... [标题] => [YomiGivenName] => [YomiSurname] => [YomiCompanyName] => [Generation] => [EmailAddresses] =>数组([0] =>数组([名称] => ... [地址] => ...))[ImAddresses] => Array()[JobTitle] => ... [CompanyName] => ... [部门] => [OfficeLocation] => ... [专业] => [BusinessHomePage] => ... [AssistantName] => [经理] => [HomePhones] =>数组() [MobilePhone1] => ... [BusinessPhones] =>数组([0] => ...) [HomeAddress] => Array()[BusinessAddress] =>数组([Street] => ... [城市] => ... [国家] => ... [CountryOrRegion] => ... [PostalCode] => ...)[OtherAddress] => Array()[SpouseName] => [PersonalNotes] => [儿童] => Array())
`PersonalNotes'每次都是空的,即使联系人中的Notes包含大量文本。
进行API调用的功能就是这个:
public function makeApiCall($method, $url, $payload = NULL) {
// Generate the list of headers to always send.
$headers = array(
"User-Agent: outlook/1.0", // Sending a User-Agent header is a best practice.
"Authorization: Bearer ".$this->access_token, // Always need our auth token!
"Accept: text/*, application/xml, application/json; odata.metadata=none", // Always accept JSON response.
"client-request-id: ".self::makeGuid(), // Stamp each new request with a new GUID.
"return-client-request-id: true", // Tell the server to include our request-id GUID in the response.
"X-AnchorMailbox: ".$this->user_email // Provider user's email to optimize routing of API call
);
// print_r($headers);
$curl = curl_init();
switch(strtoupper($method)) {
case "GET":
error_log("Doing GET");
break;
case "POST": // PAYLOAD POUR POST DOIT ETRE json_encode!!!
error_log("Doing POST");
$headers[] = "Content-Type: application/json";
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "PATCH":
error_log("Doing PATCH");
$headers[] = "Content-Type: application/json";
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "DELETE":
error_log("Doing DELETE");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
default:
error_log("INVALID METHOD: ".$method);
exit;
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
error_log("curl_exec done.");
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($httpCode >= 400) {
return array('errorNumber' => $httpCode,
'error' => 'Request returned HTTP error '.$httpCode);
}
$curl_errno = curl_errno($curl);
$curl_err = curl_error($curl);
if ($curl_errno) {
$msg = $curl_errno.": ".$curl_err;
error_log("CURL returned an error: ".$msg);
curl_close($curl);
return array('errorNumber' => $curl_errno,
'error' => $msg);
}
else {
error_log("Response: ".$response);
curl_close($curl);
return json_decode($response, true);
}
}
非常感谢任何帮助,谢谢!
答案 0 :(得分:0)
有趣。我也看到了这一点,但前提是我在桌面Outlook中设置了注释。如果我在Outlook Web App中设置它,它可以正常工作。我甚至可以在OWA中编辑'破坏'的那个并修复它。
作为临时答案,您可以编辑OWA中的联系人以修复它们。一旦我得到了更好的答案,我会更新这个答案。