I wanted to translate this code into powershell. Below is the Powershell code to request a refresh token from Google using oAtuh 2.
$CLEINTID="1234567890.apps.googleusercontent.com" $CLIENTSECRET="aBcDeFgHiJkLmNoPqRsTuVwXyZ" $REFRESHTOKEN="1/551G1yXUqgkDGnkfFk6ZbjMLMDIMxo3JFc8lY8CAR-Q" $URL = "https://accounts.google.com/o/oauth2/token" $Body= 'client_secret={0}&grant_type=refresh_token&refresh_token={1}&client_id={2}' -f $CLIENTSECRET,$REFRESH_TOKEN,$CLEINTID Invoke-RestMethod -URI $URL -Method Post -Body $Body
Hope that helps someone.
You’ve got a bug in your code there:
$Body= ‘client_secret={0}&grant_type=refresh_token&refresh_token={1}&client_id={2}’ -f $CLIENTSECRET,$REFRESH_TOKEN,$CLEINTID
Should be:
$Body= ‘client_secret={0}&grant_type=refresh_token&refresh_token={1}&client_id={2}’ -f $CLIENTSECRET,$REFRESHTOKEN,$CLEINTID
Other than that, works a treat! Thanks for sharing!! 😀