【发布时间】:2021-12-17 17:02:22
【问题描述】:
我正在编写一个脚本,该脚本将使用 Oauth 访问令牌下载 Google 表格。该脚本运行良好,但我在刷新我的访问令牌时遇到问题。
我在网上找到的每个指南都向我展示了以下内容的一些迭代:
$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
$accesstoken = $refreshedToken.access_token
当我运行此脚本时,它会返回以下内容:
StatusCode : 200
StatusDescription : OK
Content : <!doctype html><html lang="en" dir="ltr"><head><base href="https://accounts.google.com/"><script data-id="_gd" nonce="<Hidden just in case>">window.WIZ_global_data =
{"Mo6CHc":-<Hidden just in case>,"O...
RawContent : HTTP/1.1 200 OK
X-Frame-Options: DENY
Vary: Sec-Fetch-Dest, Sec-Fetch-Mode, Sec-Fetch-Site
google-accounts-embedded: 1
Pragma: no-cache
Transfer-Encoding: chunked
Strict-Transport-Security: max-...
Forms : {}
Headers : {[X-Frame-Options, DENY], [Vary, Sec-Fetch-Dest, Sec-Fetch-Mode, Sec-Fetch-Site], [google-accounts-embedded, 1], [Pragma, no-cache]...}
Images : {}
InputFields : {}
Links : {@{innerHTML=Learn more; innerText=Learn more; outerHTML=<A href="https://developers.google.com/identity/protocols/oauth2" target=_blank jsname="erTfTe">Learn more</A>;
outerText=Learn more; tagName=A; href=https://developers.google.com/identity/protocols/oauth2; target=_blank; jsname=erTfTe}, @{innerHTML=Help; innerText=Help; outerHTML=<A
href="https://support.google.com/accounts?hl=en" target=_blank>Help</A>; outerText=Help; tagName=A; href=https://support.google.com/accounts?hl=en; target=_blank},
@{innerHTML=Privacy; innerText=Privacy; outerHTML=<A href="https://accounts.google.com/TOS?loc=US&hl=en&privacy=true" target=_blank>Privacy</A>; outerText=Privacy;
tagName=A; href=https://accounts.google.com/TOS?loc=US&hl=en&privacy=true; target=_blank}, @{innerHTML=Terms; innerText=Terms; outerHTML=<A
href="https://accounts.google.com/TOS?loc=US&hl=en" target=_blank>Terms</A>; outerText=Terms; tagName=A; href=https://accounts.google.com/TOS?loc=US&hl=en; target=_blank}}
ParsedHtml : System.__ComObject
RawContentLength : 1759969
当我将此输出保存到 HTML 文件时,我得到了这个 Error 400: invalid_request
错误提示“缺少必需参数:response_type”
This Google doc 提到 response_type='code' 我已将其添加到我的数组中,但没有任何影响。
我觉得this section in the guide 应该工作,但它没有。除非我实施错误?
我在将内容类型指定为 json/application 时尝试使用“Invoke-restmethod”,我使用了替代 URI,并且我已经四次检查了我的客户端 ID 和密码。我不知道我做错了什么。
如果有人有使用 Powershell 刷新 Oauth 访问令牌的经验,我将非常感谢您的帮助。
提前致谢
【问题讨论】:
标签: powershell google-api google-oauth