![](/img/trans.png)
[英]PHP Microsoft Graph SDK: How to handle a JSON Batch Response?
[英]how to get value of contentBytes from microsoft graph sdk data response in php
我的代碼是
$expand="microsoft.graph.itemattachment/item";
$requestUrl = '/me/messages/'.$message->getId().'/attachments/?$expand= '.$expand;
$docDatas = $userClient->createCollectionRequest('GET', $requestUrl)
->setReturnType(Model\Message::class)
->setPageSize(1)
->getPage();
並想獲取outlook email附件
請幫助我的
我們得到這樣的回應
Microsoft\Graph\Model\Message Object
(
[_propDict:protected] => Array
(
[@odata.type] => #microsoft.graph.fileAttachment
[@odata.mediaContentType] => application/pdf
[id] => AAMkADE2M2FjZjMyLTY2YjAtNDQwZi1hMzc3LTI2MjYwNmQ0NTJhYwBGAAAAAAB13byROi0bTImrZtPU6w6LBwAIBVrWv6bqRZ6zXuSjdaiOAAAAAAEMAAAIBVrWv6bqRZ6zXuSjdaiOAAUI9pGdAAABEgAQABzAnt_evzNMiFTD_ANAZno=
[lastModifiedDateTime] => 2022-06-28T05:54:14Z
[name] => test.pdf
[contentType] => application/pdf
[size] => 66087
[isInline] =>
[contentId] => 6D16B02E2C840A419B9F0FEBD656E618@namprd13.prod.outlook.com
[contentLocation] =>
[contentBytes] => JVBERi0xLjQKJe...
)
)
我想獲得價值 contentBytes 但如何? 再次出現錯誤,請在此處輸入圖片描述
如果您將廣泛使用它,您可以使用CustomMessage
類擴展Message
並且為該屬性使用特定的 getter。 我的假設是您使用msgraph-sdk-php庫。
其他更簡單的解決方案是:
$expand="microsoft.graph.itemattachment/item";
$requestUrl = '/me/messages/'.$message->getId().'/attachments/?$expand= '.$expand;
$docDatas = $userClient->createCollectionRequest('GET', $requestUrl)
->setReturnType(Model\Message::class)
->setPageSize(1)
->getPage();
$properties = $docDatas->getProperties();
$contentBytes = $properties["contentBytes"];
Message 擴展OutlookMessage
擴展Microsoft\Graph\Model\Entity
。 您可以在該類中找到getProperties
方法。
use GuzzleHttp\Psr7\Stream; use Microsoft\Graph\Model\Message; use Microsoft\Graph\Model\Attachment; $filename = 'my_file.jpg'; $filepath = '/path/to/file/my_file.jpg'; $filetype = mime_content_type($filepath); $stream = Stream(fopen($filepath, 'r+')); $file_attachement = new FileAttachment(); $file_attachement->setODataType('#microsoft.graph.fileAttachment'); $file_attachement->setName($filename); $file_attachement->setContentType($filetype); $file_attachement->setContentBytes(base64_encode($stream)); $message = new Message(); $message->setAttachments(array($file_attachement));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.