使用 PowerShell 为 Microsoft Graph 创建编码的 Url

问题描述 投票:0回答:0

我已将文件上传到 OneDrive 并添加了邀请用户访问该文件。共享 Url 适用于该用户。我想使用相同的 Url 并授予其他用户访问该文件的权限。

看起来我应该能够使用以下请求通过该链接添加其他用户访问权限。 POST /shares/{encoded-sharing-url}/permission/grant https://learn.microsoft.com/en-us/graph/api/permission-grant?view=graph-rest-1.0&tabs=http

我在获取图形将接受的编码 Url 时遇到问题。我所有的请求都收到了以下回复。

{
  "error": {
    "code": "invalidRequest",
    "message": "The provided shares id is not valid.",
    "innerError": {
      "code": "badArgument",
      "date": "2023-02-21T04:50:01",
      "request-id": "85e712ce-efd7-4d42-8cde-1b7133adaa9e",
      "client-request-id": "85e712ce-efd7-4d42-8cde-1b7133adaa9e"
    }
  }
}

我一直在使用以下示例在 base64 中进行编码 https://shellgeek.com/powershell-base64-encoding/#PowerShell_Base64_Encode_String:~:text=files%20in%20PowerShell!-,PowerShell%20Base64%20Encode%20String,-Let%E2%80%99s%20understand%20with

$StringMsg = "PowerShell Base64 Encode Example"
# Gets the bytes of String
$StringBytes = [System.Text.Encoding]::Unicode.GetBytes($StringMsg)
# Encode string content to Base64 string
$EncodedString =[Convert]::ToBase64String($StringBytes)
Write-Host "Encode String: " $EncodedString

确保将 / 替换为 _ 并将 + 替换为 - 并确保末尾没有 =。

是否有正确编码的技巧?

powershell microsoft-graph-api base64 httprequest
© www.soinside.com 2019 - 2024. All rights reserved.