Reputation: 5941
I have the following spreadsheet which requires authentication:
https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYuYNefv9cOJ_7afTLImHgYA05pfN3qY63E
Using the following URL in a browser automatically converts it to CSV and downloads it: https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYuYNefv9cOJ_7afTLImHgYA05pfN3qY63E/export?format=csv
I'm trying to do the same using Powershell. I have managed to acquire an Access Token from googleapi using the following function:
function Get-AccessToken{
$RefreshTokenParams = @{
client_id=$clientId;
client_secret=$secret;
refresh_token=$refreshToken;
grant_type=’refresh_token’;
}
$RefreshedToken = Invoke-WebRequest -Uri “https://accounts.google.com/o/oauth2/token” -Method POST -Body $refreshTokenParams -ErrorAction Stop | ConvertFrom-Json
return ($refreshedToken.access_token)
}
$ClientID = "zzzzzzzzzzzzzzzzzzzzzzlobe.apps.googleusercontent.com";
$Secret = "sssssssssssssssssssssss";
$RedirectURI = "urn:ietf:wg:oauth:2.0:oob";
$AuthorizationCode = 'xxxxxxxxxxxxxxxxxxxxx';
$AccessToken = Get-AccessToken
Now my question is how do I use Invoke-Command to access the link provided earlier along with my access token.
Upvotes: 0
Views: 6888
Reputation: 201338
With powershell, you want to download the spreadsheet as a CSV file using the access token. And you have already been able to use the access token. If my understanding is correct, how about this script?
Invoke-WebRequest -Uri "https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYuYNefv9cOJ_7afTLImHgYA05pfN3qY63E/export?format=csv&access_token=### access token ###" -OutFile "### filename.csv ###"
https://www.googleapis.com/auth/drive
was included in the scopes.If I misunderstand your question, I'm sorry.
Upvotes: 2