我们正在使用outlook图形api来读取消息。证件和其他东西都很好。但是当我们使用带有patch方法的api时它会返回。访问被拒绝。请检查凭据并重试。
我们正在使用的范围OFFICE365_SCOPES='https://graph.microsoft.com/.default'
public function setMessageAsSeen($userName, $msgId){
try{
if( ! $this->msLogin()){
return [];
}
$ch = curl_init();
$url = "https://graph.microsoft.com/v1.0/users/".$userName."/messages/".$msgId;
$request_headers = array();
$request_headers[] = 'Content-type: application/json';
$request_headers[] = 'Authorization: Bearer '.$this->accessToken;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['isRead' => true]));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$response = curl_exec($ch);
dd($response);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpCode != 200) {
return false;
}
return true;
}catch(Exception $e){
Log::error('setMessageAsSeen() error : '.$e->getMessage());
return false;
}
}
请求相同的指南。
GET /users/{id | userPrincipalName}/messages
需要Mail.ReadBasic.All
请看这里:https://learn.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0&tabs=http
PATCH /users/{id | userPrincipalName}/messages/{id}
需要Mail.ReadWrite
.
请看这里:https://learn.microsoft.com/en-us/graph/api/message-update?view=graph-rest-1.0&tabs=http