【发布时间】:2017-04-03 18:29:52
【问题描述】:
我一直在尝试将 Outlook 365 中的所有联系人导入另一个数据库。我可以毫无问题地获取所有姓名、电子邮件、地址等。
但是,当我想获取位于 Outlook 365 联系人第二页上的便笺时,它们显示为空。
我正在使用 PHP 代码,使用此 URL 调用 API:
https://outlook.office.com/api/v2.0/Me/Contacts
没有特定的参数。所有登录、令牌等部分都得到妥善处理。
这是我当前通过 print_r 调用收到的数组示例:
数组([Id] => ... [CreatedDateTime] => ... [LastModifiedDateTime] => ... [ChangeKey] => ... [Categories] => 数组([0] => ...) [ParentFolderId] => ... [生日] => [FileAs] => ... [DisplayName] => ... [GivenName] => ...[姓名首字母] => [MiddleName] => [NickName] => ... [姓氏] => ... [职称] => [YomiGivenName] => [YomiSurname] => [YomiCompanyName] => [Generation] => [EmailAddresses] => 数组([0] => Array ([Name] => ...[Address] => ...) ) [ImAddresses] => Array ( ) [JobTitle] => ... [CompanyName] => ... [Department] = > [办公地点] => ...[职业] => [企业主页] => ... [AssistantName] => [Manager] => [HomePhones] => 数组 ( ) [MobilePhone1] => ... [BusinessPhones] => 数组([0] => ...) [HomeAddress] => 数组 ( ) [BusinessAddress] => 数组 ( [Street] => ... [城市] => ...[州] => ...[CountryOrRegion] => ...[PostalCode] => ...) [OtherAddress] => 数组 () [SpouseName] => [PersonalNotes] => [儿童] => 数组 ( ) )
`PersonalNotes' 每次都是空的,即使联系人中的便笺包含大量文本。
进行 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);
}
}
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: php outlook outlook-restapi