我只想通过 Graph API 为我的 OneDrive for Business 帐户创建一个文件夹。几个小时后,我遇到了一个我真的无法理解的错误。它说“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 个小时._。