Google SpreadSheet API和Powershell-转换为CSV [英] Google SpreadSheet API and Powershell - Convert to CSV

查看:80
本文介绍了Google SpreadSheet API和Powershell-转换为CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下需要验证的电子表格:

I have the following spreadsheet which requires authentication:

https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYYYNF>

https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYuYNefv9cOJ_7afTLImHgYA05pfN3qY63E

在浏览器中使用以下URL会自动将其转换为CSV并下载: https://docs.google.com/spreadsheets/d/1wDD_Xef3QY3YF export?format = csv

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

我正在尝试使用Powershell进行相同的操作. 我已经成功使用以下功能从googleapi获取了访问令牌:

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

现在我的问题是如何使用Invoke-Command来访问前面提供的链接以及访问令牌.

Now my question is how do I use Invoke-Command to access the link provided earlier along with my access token.

推荐答案

使用powershell,您希望使用访问令牌将电子表格下载为CSV文件.您已经可以使用访问令牌.如果我的理解是正确的,那么该脚本怎么样?

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 ###"

注意:

  • 下载文件时,如果发生错误,请确认以下几点.
    • 是否在API控制台上启用了Drive API.
    • https://www.googleapis.com/auth/drive是否包含在范围中.
    • Note :

      • When you download the file, if the error occurs, please confirm the following points.
        • Whether Drive API was enabled at API console.
        • Whether https://www.googleapis.com/auth/drive was included in the scopes.
        • 如果我误解了你的问题,对不起.

          If I misunderstand your question, I'm sorry.

          这篇关于Google SpreadSheet API和Powershell-转换为CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆