我正在编写一个将使用Microsoft Graph API的脚本(使用此库https://github.com/microsoftgraph/msgraph-sdk-php)
我设法连接和搜索特定的电子邮件,下载附件,但现在我需要标记电子邮件为已读,并设置标志,但我不知道如何。
到目前为止,我已经使用这个教程(https://learn.microsoft.com/en-us/graph/tutorials/php?tabs=aad),以便连接和阅读电子邮件。
public static function getInbox() {
$token = GraphHelper::getUserToken();
GraphHelper::$userClient->setAccessToken($token);
// Only request specific properties
$select = '$select=from,isRead,receivedDateTime,subject,hasAttachments';
// Sort by received time, newest first
$orderBy = '$orderBy=receivedDateTime DESC';
$filter = '$filter=isRead eq false';
$requestUrl = '/me/mailFolders/inbox/messages?'.$filter.'&'.$select.'&'.$orderBy;
$messages = GraphHelper::$userClient->createCollectionRequest('GET', $requestUrl)
->setReturnType(Model\Message::class)
->setPageSize(100)
->getPage();
foreach ($messages as $message) {
if(strpos($message->getSubject(), 'XML')!==false ){
print('Message: '.$message->getSubject().PHP_EOL);echo PHP_EOL;
$expand="microsoft.graph.itemattachment/item";
$requestUrl = '/me/messages/'.$message->getId().'/attachments/?$expand= '.$expand;
$docDatas = GraphHelper::$userClient->createCollectionRequest('GET', $requestUrl)
->setReturnType(Model\Message::class)
->setPageSize(1)
->getPage();
$dat = $docDatas[0]->getProperties();
//parseXmlOrder(base64_decode($dat['contentBytes']));
$sendBody = array( 'isRead' => true );
var_dump( GraphHelper::$userClient->createRequest('PATCH', '/me/messages/'.$message->getId())
->attachBody($sendBody)
->execute() );
}
}
}
这是我目前拥有的代码,在函数的最后我尝试设置isRead属性。
如果有人能给予我一些建议,我哪里错了,这将是惊人的,并帮助我停止撞我的头撞墙。
谢谢你,
1条答案
按热度按时间nbnkbykc1#
原来给读写权限确实有帮助。我只有读权限。