在 PowerShell 中通過 HttpWebRequest 共享資料夾
$url = "https://api.dropboxapi.com/2/sharing/share_folder"
$req = [System.Net.HttpWebRequest]::Create($url)
$req.headers["Authorization"] = "Bearer <ACCESS_TOKEN>"
$req.Method = "POST"
$req.ContentType = "application/json"
$enc = [system.Text.Encoding]::UTF8
$params = @{path="/new shared folder path"} | ConvertTo-Json -compress
$params = $enc.GetBytes($params)
$req.GetRequestStream().Write($params, 0, $params.Length)
$res = $req.GetResponse()
Write-Host "Response Status Code: "$res.StatusCode
Write-Host "Response Status Description: "$res.StatusDescription
$readStream = new-object System.IO.StreamReader $res.GetResponseStream()
$result = $readStream.ReadToEnd() | ConvertFrom-Json
Write-Host $result
$readStream.Close()
$res.Close()
應該用你的訪問令牌替換 <ACCESS_TOKEN>
。