【发布时间】:2019-04-05 06:56:48
【问题描述】:
我正在使用googleapis npm 库授权使用 OAuth2 访问我的 Gmail 帐户以发送电子邮件。我正在使用以下代码(TypeScript)来做到这一点:
const oAuth2Client = new google.auth.OAuth2(
googleConfig.clientId,
googleConfig.clientSecret
);
oAuth2Client.setCredentials({
refresh_token: googleConfig.refreshToken
});
const accessTokenRetVal = (await oAuth2Client.refreshAccessToken()).credentials.access_token;
const accessToken = accessTokenRetVal || '';
此代码有效,但我收到以下消息:
(node:8676) [google-auth-library:DEP007] DeprecationWarning: The `refreshAccessToken` method has been deprecated, and will be removed in the 3.0 release of google-auth-library. Please use the `getRequestHeaders` method instead.
我在 Google、GitHub 上搜索了 googleapis 模块、在 StackOverflow 上,但我无法找到任何有关 getRequestHeaders 方法的文档。我尝试调用getRequestHeaders,但它似乎没有返回带有访问令牌的credentials 对象。
是否有官方文档说明在这种情况下应该如何使用getRequestHeaders?
【问题讨论】:
标签: google-api-nodejs-client google-auth-library