[英]Google OAuth2 client timeout when calling getToken in nodejs
I was using Google API to do oauth2.我正在使用 Google API 来做 oauth2。 The app key Id and secret have been set up, and the URL was created successfully using
oauth2Client.generateAuthUrl
.已设置应用密钥 ID 和密钥,并且使用
oauth2Client.generateAuthUrl
成功创建了 URL。
let {google} = require('googleapis'),
contacts = google.people('v1'),
oauth2Client = new google.auth.OAuth2(
"MY_KEY",
"MY_SECRET",
"http://localhost:8886/mbl/User/ImportContact"
),
scopes = [
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/calendar'
],
url = oauth2Client.generateAuthUrl({
access_type: 'online',
scope: scopes
});
In the URL, I authorized the access, and then was redirected to the designated oauthcallback method.在 URL 中,我授权了访问,然后被重定向到指定的 oauthcallback 方法。 The code was in format of
代码格式为
4/AADYYeZzY38aKLr1g11IBN2d_9keAdtN2JhDU1WH5pHAPi_0ECfRVS4a-oDiCE5IHPiB3SnyJ4p59ZEFOOSEDFQ#
4/AADYYeZzY38aKLr1g11IBN2d_9keAdtN2JhDU1WH5pHAPi_0ECfRVS4a-oDiCE5IHPiB3SnyJ4p59ZEFOOSEDFQ#
which looks right.看起来不错。
However, the code execution got stuck at the oauth2Client.getToken
.但是,代码执行卡在
oauth2Client.getToken
。 It never gets past the following line它永远不会超过以下行
const {tokens} = await oauth2Client.getToken(code)
After a while, it gives me timeout error:过了一会儿,它给了我超时错误:
Error: connect ETIMEDOUT 216.58.199.10:443
错误:连接 ETIMEDOUT 216.58.199.10:443
Could someone kindly help me with it?有人可以帮助我吗? I have been struggling with it all day.
我一整天都在为此苦苦挣扎。
oAuth2Client.getToken probably returns the desired token in a callback from where you can capture it. oAuth2Client.getToken 可能会在回调中返回所需的令牌,您可以从中捕获它。 You may wish to promisify it before you use async - await with it.
您可能希望在使用 async 之前承诺它 - 等待它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.