I want to call Google APIs from Powershell. The google documentation says:
curl \"https://accounts.google.com/o/oauth2/token\"
-d \"client_id=$CLIENT_ID&c
Theoretically you use Invoke-WebRequest right as the POST request's body should have application/x-www-form-urlencoded content type which is set by default in PS.
I executed the same code and I got a 401 request, because my auth parameters doesn't match. I also checked it in Fiddler too and the message is constructed correctly
Mine Fiddler captured Invoke-WebRequest POST message looks like:
POST https://accounts.google.com/o/oauth2/token HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.4; hu-HU) WindowsPowerShell/5.0.9879.0
Content-Type: application/x-www-form-urlencoded
Host: accounts.google.com
Content-Length: 113
Expect: 100-continue
Connection: Keep-Alive
grant_type=authorization_code&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&code=z&client_id=x&client_secret=y
According to Google's oauth sample message ( https://developers.google.com/accounts/docs/OAuth2ForDevices ) this is correct, so I would check your call in Fiddler too.