我只想通过Graph API在OneDrive for Buiness帐户中创建一个文件夹。很多小时后,我陷入了一个我无法理解的错误。它说属性“ Attributes”在类型“ oneDrive.folder”上不存在,我不应该使用此属性。问题是我不使用此属性。经过大量研究,我认为这与固定的元数据有关。但是在一般情况下,我真的不知道该怎么办。
我使用Graph Explorer和另一个网站来创建此脚本。
错误:
-1, Microsoft.SharePoint.Client.InvalidClientQueryException
The property 'Attributes' does not exist on type 'oneDrive.folder'.
Make sure to only use property names that are defined by the type.
这是我的代码:
$clientId = "XXXXXXXXXXXXXX"
$tenantId = "XXXXXX.onmicrosoft.com"
$clientSecret = 'XXXXXXXXXXXX'
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
$body = @{
client_id = $clientId
scope = "https://graph.microsoft.com/.default"
client_secret = $clientSecret
grant_type = "client_credentials"
}
$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
Write-Host $token
$uri = "https://graph.microsoft.com/v1.0/<ID XXXXXXX>/drive/root/children"
$method = 'POST'
$head= @{Authorization = "Bearer $token"}
$postPara= @{
name= "NewFolder"
folder= {}
} | ConvertTo-Json
$antwort = Invoke-RestMethod -Headers $head -Uri $uri -Method $method -Body $postPara -ContentType "application/json"
Write-Host $antwort
它确实应该工作,并且我正在执行此示例任务超过10个小时。_。
答案 0 :(得分:1)
与您的代码有关的问题是
$postPara= @{
name= "NewFolder"
folder = {}
} | ConvertTo-Json
如果仅输出$ postPara,您将看到问题是因为在文件夹中的值前面缺少@,您实际上将从那里填充的基础脚本中获取详细信息。所以尝试
$postPara= @{
name= "NewFolder"
folder = @{}
} | ConvertTo-Json
$postPara
应该修复它。一个好的诊断工具也是使用fiddler查看发送到服务器的请求。