当我在PowerShell中提供此功能时:
Invoke-RestMethod -Uri "https://outlook.office365.com/api/v1.0/users/andrew.stevens@mydomain.com/folders/"
-Credential $cred | foreach-object{$_.value |select DisplayName,ID}
我成功确定了文件夹ID,但并非所有文件夹都可见。如何获得完整的文件夹列表(我特别想要的是可恢复的项目)。我在想到ID后会想到文件夹中包含的消息吗?
答案 0 :(得分:0)
您的意思是已删除邮件文件夹吗? 如果我理解正确,它应该由您调用的REST列出。我们可以使用众所周知的文件夹名称: DeletedItems 来获取消息。以下是供您参考的示例:
Get: https://outlook.office.com/api/v2.0/me/MailFolders/DeletedItems/messages
要使用Office 365 REST API,我们需要使用首先注册应用程序所需的承载令牌。以下是通过PowerShell获取访问令牌供您参考的示例(请参阅Obtaining an Access Token):
#region Construct Azure Datamarket access_token
#Get ClientId and Client_Secret from https://datamarket.azure.com/developer/applications/
#Refer obtaining AccessToken (http://msdn.microsoft.com/en-us/library/hh454950.aspx)
$ClientID = '<Your Value Here From Registered Application>'
$client_Secret = ‘<Your Registered Application client_secret>'
# If ClientId or Client_Secret has special characters, UrlEncode before sending request
$clientIDEncoded = [System.Web.HttpUtility]::UrlEncode($ClientID)
$client_SecretEncoded = [System.Web.HttpUtility]::UrlEncode($client_Secret)
#Define uri for Azure Data Market
$Uri = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13"
#Define the body of the request
$Body = "grant_type=client_credentials&client_id=$clientIDEncoded&client_secret=$client_SecretEncoded&scope=http://api.microsofttranslator.com"
#Define the content type for the request
$ContentType = "application/x-www-form-urlencoded"
#Invoke REST method. This handles the deserialization of the JSON result. Less effort than invoke-webrequest
$admAuth=Invoke-RestMethod -Uri $Uri -Body $Body -ContentType $ContentType -Method Post
#Construct the header value with the access_token just recieved
$HeaderValue = "Bearer " + $admauth.access_token
#endregion
#region Construct and invoke REST request to Microsoft Translator Service
[string] $text = "Use pixels to express measurements for padding and margins.";
[string] $textEncoded = [System.Web.HttpUtility]::UrlEncode($text)
[string] $from = "en";
[string] $to = "de";
[string] $uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + $text + "&from=" + $from + "&to=" + $to;
$result = Invoke-RestMethod -Uri $uri -Headers @{Authorization = $HeaderValue}
#endregion
$result.string.'#text'
获取访问令牌后,我们可以使用下面的示例进行REST调用:
$uri ="https://outlook.office.com/api/v2.0/me/MailFolders/DeletedItems/messages"
$accessToken=''
Invoke-RestMethod -Uri $uri -Headers @{Authorization=("bearer {0}" -f $accessToken)}
以下链接也有助于您学习Office 365 REST API:
Manually register your app with Azure AD so it can access Office 365 APIs
答案 1 :(得分:0)
感谢您的评论,是的DeletedItems将是文件夹名称(对于已删除的项目),但我发现了这个..
https://msdn.microsoft.com/en-us/library/office/dn424760(v=exchg.150).aspx。
从此可以做到这一点..
Invoke-RestMethod -Uri&#34; https://outlook.office365.com/api/v1.0/users/andrew.stevens@anydomain.com/folders/recoverableitemsdeletions/messages? &#34; -Credential $ cred | foreach-object {$ .value | select @ {n =&#39; Sender&#39 ;; e = {$ .sender.emailaddress.name}},Subject,DateTimeReceived}
因此,这会在已恢复的已删除邮件容器中获取邮件。
现在问题是如何将它们移至收件箱?
// A
答案 2 :(得分:0)
好的..感谢有关应用注册和OAuth的信息。但只是为了查看恢复的已删除项目,使用v1.0的方法确实有效。 我现在需要理解的是(我对此缺乏了解的道歉)是如何从位于(恢复的已删除项目)的文件夹中移动邮件来说明收件箱(或者可能是另一个选择的文件夹)。由于我能够使用V1.0(不需要应用程序注册),我可以使用相同的版本来执行此操作吗? 您提供的发送电子邮件的答案完美无缺,并且不需要任何应用程序注册..所以这将是某个人的帖子..
我必须继续下去 1.发布https://outlook.office.com/api/v1.0/me/messages/ {message_id} / move 2. { &#34; DestinationId&#34;:&#34; AAMkAGI2NGVhZTVlLTI1OGMtNDI4My1iZmE5LTA5OGJiZGEzMTc0YQAuAAAAAADUuTJK1K9aTpCdqXop_4NaAQCd9nJ-tVysQos2hTfspaWRAAAAAAEJAAA =&#34; }
哪个是文件夹ID
// A