Google 用于刷新访问令牌的电子表格应用程序脚本

Google Spreadsheet App script to refresh the access token

我正在使用以下 HTTP 请求从关联的 YouTube 频道检索数据。

https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3D{MY_ASSOCIATED_CHANNEL_ID}&start-date=2016-08-01&end-date=2016-08-31&metrics=views&dimensions=video&filters=video%3D%3D{MY_VIDEO_ID}&max-results=10&sort=-views& access_token= {MY_ACCESS TOKEN}

我正在使用 google 电子表格应用程序脚本来处理上述请求。

你能帮我设置一个额外的功能,它将在 运行 上述功能之前刷新我的访问令牌(我已经有一个刷新令牌)

谢谢,

阿尼什

您可以查看此 GitHub tutorial 如何在令牌过期时刷新令牌。

OAuth2 for Apps Script is a library for Google Apps Script that provides the ability to create and authorize OAuth2 tokens as well as refresh them when they expire. This library uses Apps Script's new StateTokenBuilder and /usercallback endpoint to handle the redirects.

对于此库(以及一般的 Apps 脚本功能),URL 将始终采用以下格式:

https://script.google.com/macros/d/{SCRIPT ID}/usercallback

其中 {SCRIPT ID} 是使用该库的脚本的 ID。您可以通过点击菜单项 "File > Project properties".

在 Apps 脚本代码编辑器中找到您的脚本 ID

为此,请按照上面提供的 link 中的步骤操作。希望这对您有所帮助!