我试图从MS Office 365资源日历中检索信息。
我使用下面显示的代码,并返回一个字符串。我想把它作为JSON提要。或者如果JSON不可能,则为数组,因为我打算在&full.calendar'
上显示结果任何人都知道这个伎俩。
CODE:
$username = 'user@domain.com'; // User with delegate control.
$password = 'P@ssword';
$calendar = 'ressourceRoom@domain.com';
$URL = 'https://outlook.office365.com/api/v1.0/users/'.$calendar.'/calendarview?startDateTime=05/30/2016&endDateTime=06/13/2016';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result= (curl_exec ($ch));
curl_close ($ch);
echo gettype($result)."<br /><br /><br />";
print_r($result);
结果(刚刚开始显示)。:
string
{"@odata.context":"https://outlook.office365.com/api/v1.0/$metadata#Users('room@domain.com')/CalendarView","value":[{"@odata.id":"https://outlook.office365.com/api/v1.0/Users('room@domain.com')/Events('AAMkADBiMmM3NjE5LTUyMDUtNDY0Mi1hNjAyLTY2M2ZlYmM3OTkwOQBGAAAAAAAnzkQlYPmYQ4MtD6sjQqO8BwAaVyh143FwQZzopix2q_v7AAAAAAENAAAaVyh143FwQZzopix2q_v7AAAAAA0eAAA=')","@odata.etag":"W/\"GlcodeNxcEGc6KYsdqvr+wAAAAAMVg==\"","Id":"AAMkADBiMmM3NjE5LTUyMDUtNDY0Mi1jAyLTY2M2ZlYmM3OTkwOQBGAAAAAAAnzkQlYPmYQ4MtD6sjQqO8BwAaVyh143FwQZzopix2q_v7AAAAAAENAAAaVyh143FwQZzopix2q_v7AAAAAA0eAAA=","DateTimeCreated":"2016-06-06T12:07:57.398966Z","DateTimeLastModified":"2016-06-06T12:07:57.8833477Z","ChangeKey":"GlcodeNxcEGc6KYsdqvr+wAAAAAMVg==","Categories":[],"StartTimeZone":"Romance Standard Time","EndTimeZone":"Romance Standard Time","ResponseStatus":{"Response":"Accepted","Time":"2016-06-06T12:07:57.6489687Z"},"iCalUId" ....
答案 0 :(得分:0)
从Office 365 REST获得的HTTP响应已返回JSON格式字符串。根据代码,您似乎正在使用PHP进行开发。我们需要根据我们开发的语言,通过库将JSON格式字符串转换为JSON对象。
例如,我们可以使用json_decode($ string)将String转换为PHP中的Array / Object。有关详细信息,请参阅here。