-1
我想從Powershell調用Google API。谷歌文檔說:使用Powershell調用Google API
curl "https://accounts.google.com/o/oauth2/token"
-d "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&code=$CODE&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
哪些工作從命令行執行時。
我試圖將它轉換爲PowerShell的,如:
$token = Invoke-WebRequest -Uri "https://accounts.google.com/o/oauth2/token" -Method POST -Body "client_id=x&client_secret=y&code=z&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
而像:
$tokenParams = @{
client_id='x';
client_secret='y';
code='z';
grant_type='authorization_code';
redirect_uri='urn:ietf:wg:oauth:2.0:oob'
}
$token = Invoke-WebRequest -Uri "https://accounts.google.com/o/oauth2/token" -Method POST -Body $tokenParams
都返回:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
如何正確地轉換捲曲Invoke- WebRequest或其他PS cmdlet?
另請參閱我在Powershell V3及更高版本中可用的「Invoke-RestMethod」。 – Eris
但是,真正的問題在於,您將對象作爲一個主體傳遞。所有Google的API都需要這些參數,它們位於請求標題中,而不是主體。另外,你有沒有看過這個免費的PowerShell API實現https://github.com/squid808/gShell/ – Eris