互聯網上基本上沒有關于如何將照片上傳到 Google 相冊的 Powershell 代碼示例。
根據檔案,上傳媒體專案是一個兩步程序:
將原始位元組上傳到 Google 服務器。這不會導致在用戶的 Google 相冊帳戶中創建任何媒體專案。相反,它回傳一個上傳令牌,用于標識上傳的位元組。
使用上傳令牌在用戶的 Google 相冊帳戶中創建媒體專案。您可以選擇是否還應將媒體添加到特定相冊。有關更多資訊,請參閱創建相冊。
至于第 1 點,上傳 RAW 位元組有點棘手,因為沒有 Powershell 樣本!
使用上傳請求將位元組上傳到 Google。如果上傳請求成功,則回傳原始文本字串形式的上傳令牌。要創建媒體專案,請在 batchCreate 呼叫中使用這些令牌。
您如何正確設定正文,其中應包含正在上傳的影像的二進制資料?
例如
### token auth code intentionally removed ###
$method = "POST"
$requestUri = "https://photoslibrary.googleapis.com/v1/uploads"
$Headers = @{
Authorization = "Bearer $access_token";
ContentType = "application/octet-stream";
"X-Goog-Upload-Content-Type" = "mime-type";
"X-Goog-Upload-Protocol" = "raw";
}
$body = ?????? <<<<<<<<<<< What here?
try {
$Response = Invoke-RestMethod -Headers $Headers -Body $body -Uri $requestUri -Method $method
}
catch {
$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$ErrResp = $streamReader.ReadToEnd() | ConvertFrom-Json
$streamReader.Close()
}
uj5u.com熱心網友回復:
在你的情況下,下面的修改如何?
從:
$body = ?????? <<<<<<<<<<< What here?
try {
$Response = Invoke-RestMethod -Headers $Headers -Body $body -Uri $requestUri -Method $method
}
到:
$body = "SampleFilenameWithPath"
try {
$Response = Invoke-RestMethod -Headers $Headers -InFile $body -Uri $requestUri -Method $method
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/393502.html
