我正在使用Office 365在用户日历中发布活动。我的帖子格式有问题。
这是我的代码(使用Codeigniter和Rest lib):
$config = array (
'server' => 'https://outlook.office365.com/api/v1.0/me',
'http_user' => 'mail@domain.com',
'http_pass' => 'mypassword',
'http_auth' => 'basic',
);
$this->load->library('rest', $config);
$event = array(
'Subject' => 'Try to post :(',
'Body' => array(
'ContentType' => 'HTML',
'Content' => 'Not really concluant...'),
'Start' => "2015-04-22T18:00:00Z",
'End' => "2015-04-22T19:00:00Z",
'StartTimeZone' => 'Europe Standard Time',
'EndTimeZone' => 'Europe Standard Time',
);
var_dump($this->rest->post('events', json_encode($event), 'json'));
以下是回复:
找不到与内容类型匹配的受支持的MIME类型 的回应。没有支持的类型 “应用程序/ JSON; odata.metadata =最小
我做错了什么?请不要说全部!
答案 0 :(得分:0)
我不确定“欧洲标准时间”是否正确。请在“时区”列中的here列表中指定时区。
答案 1 :(得分:0)
您需要将Content-Type
标头设置为application/json
。我不确定如何使用该特定API,但这听起来像是你的问题。
答案 2 :(得分:0)
我一直在寻找同样的解决方案,然后我找到了:
首先需要具有“所有者”权限的用户才能创建您要创建的日历 (您可以使用管理员帐户进行测试) 然后你需要在base64中编码你的登录密码 转到这个网站,你可以在线完成 http://www.tools4noobs.com/online_php_functions/base64_encode/
然后选择“base64encode” 像这个例子一样写在盒子里面: john.smith@domain.com:密码
复制结果:示例 am9obi5zbWl0aEBkb21haW4uY29tOnBhc3N3b3Jk
1步:读取事件(在php中):
<?
$mail = "eric.blik@domain.com"; // agenda email you want to check
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: Basic am9obi5zbWl0aEBkb21haW4uY29tOnBhc3N3b3Jk"
// replace after basic by the password
)
);
$context = stream_context_create($opts);
$ret_event = file_get_contents("https://outlook.office365.com/api/v1.0/users/" . $mail . "/calendarview?startDateTime=2015-06-30T09:00:00Z&endDateTime=2015-06-30T18:00:00Z", false, $context);
echo "<pre>";
print_r(json_decode($ret_event));
echo "</pre>";
?>
第二步:写事件(在php中):
<?
$mail = "eric.blik@domain.com"; // agenda email you want ot add event
$url = "https://outlook.office365.com/api/v1.0/users/" . $mail . "/events";
$fuseau = date("P");
$titre = "Hello"; // Title
$description = "Welcome to our world"; // Content can be html
// Time zone is for France, check yours
// Change the date time for your event
$data_json = '{ "Subject": "' . $titre . '",
"Body": {
"ContentType": "HTML",
"Content": "' . $description . '"
},
"Start": "2015-07-07T18:00:00' . $fuseau . '",
"StartTimeZone": "Romance Standard Time",
"End": "2015-07-07T19:00:00' . $fuseau . '",
"EndTimeZone": "Romance Standard Time",
"Attendees": [
{
"EmailAddress": {
"Address": "' . $mail . '",
"Name": "TEST"
},
"Type": "Required"
}
]
}';
$options = array("http" => array( "method" => "POST",
"header" => "Authorization: Basic am9obi5zbWl0aEBkb21haW4uY29tOnBhc3N3b3Jk\r\n" .
"Content-type: application/json\r\n",
"content" => $data_json
));
$context = stream_context_create($options);
$retour_create_event = file_get_contents($url, false, $context);
echo "<pre>";
print_r(json_decode($retour_create_event));
echo "</pre>";
$id = json_decode($retour_create_event)->Id;
echo "Id of the event : " . $id;
?>
现在查看你的日程,你将有你的活动 您可以添加很多设置,例如类别或其他信息
它适用于电子邮件,Onenote和Sharepoint。
等待您的反馈