Call Google API with Powershell

前端 未结 1 1691
面向向阳花
面向向阳花 2021-01-29 09:54

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         


        
1条回答
  •  野的像风
    2021-01-29 10:26

    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.

    0 讨论(0)
提交回复
热议问题