如何解决如何使用Graph API和PowerShell将OneNote笔记本选项卡添加到Teams通道?
我正在尝试使用Graph API将包含OneNote笔记本的选项卡添加到我的MS Teams频道中。 我发现此usefull blog post解释了如何执行此操作。不幸的是,我没有设法结束。 无论他是什么意思,我都坚持要他在团队中创建OneNote。
这是我的Microsoft Graph Explorer窗口的图片:
仅供参考,我的“请求正文”部分包含以下代码:
{
"displayName": "OneNote"
}
这是我的PowerShell。未初始化的变量具有实际值(个人或与此职位无关)。它们定义正确,因为我得到了我想要的一切。只有最后一个请求调用不起作用。
$graphAPIUrl = "https://graph.microsoft.com/v1.0/"
$teamTitle = "My teams"
# Connecting to AzureAD Services
Connect-AzureAD -Credential $creds
# Connecting to Graph API services
Connect-PnPOnline -ClientId $GraphAppId -ClientSecret $GraphAppSecret -AADDomain $AADDomain
# Getting access token
$token = Get-PnPGraphAccessToken
$headers = @{
"Authorization"="Bearer " + $token;
"Content-Type"= "application/json";
"Content-length" = 200;
}
# Getting current team group ID
$getAllGroupsRequest = "$($graphAPIUrl)groups"
$groups = Invoke-RestMethod -Uri $getAllGroupsRequest -Headers $headers -Method "GET"
$groupId = ($groups.value | Where-Object displayName -eq $teamTitle).id
# Getting site collection ID
$getRootSiteInfoRequest = "$($graphAPIUrl)groups/$($groupId)/sites/root"
$siteCollectionInfos = Invoke-RestMethod -Uri $getRootSiteInfoRequest -Headers $headers -Method "GET"
# Getting site ID
$siteCollectionId = (($siteCollectionInfos.value).id -Split ",")[1]
$siteId = (($siteCollectionInfos.value).id -Split ",")[2]
# Creating the notebook in teams
$createNoteBookRequest = "$($graphAPIUrl)groups/$($groupId)/onenote/notebooks"
$body = @{
"displayName" = "OneNote"
}
$formatedBody = ConvertTo-Json -InputObject $body
$createdGroup = Invoke-RestMethod -Uri $getRootSiteInfoRequest -Headers $headers -Method "POST" -Body $body
启动上面的代码段时,我收到以下消息:
Invoke-RestMethod : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse
我在做什么错了?
解决方法
Invoke-RestMethod适用于“ GET”操作,但似乎不适用于POST操作,因此请尝试将上面发布的最后一行,即带有“ body”的Invoke-WebRequest转换为
$createdGroup = Invoke-WebRequest -Uri -Headers $headers -ContentType 'application/json' -Method "POST" -Body $body
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。