Powershell에서 Google API를 호출하고 싶습니다. Google 설명서에서 다음과 같이 말합니다.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