下面是https://github.com/google/google-api-nodejs-client的代码。
oauth2Client.credentials = {
access_token: 'ACCESS TOKEN HERE',
refresh_token: 'REFRESH TOKEN HERE'
};
client
.plus.people.get({ userId: 'me' })
.withAuthClient(oauth2Client)
.execute(callback);
一般问题:刷新令牌实际上如何与访问令牌一起工作?
背景:根据我的解释,每个访问令牌都有一个有限的时间跨度(~1小时)。因此,当用户第一次连接到我的服务器(服务器为用户身份验证提供了机制)时,服务器将收到有限生命期访问令牌和一次性刷新令牌。1小时后,访问令牌过期。
谢了!
var hasAuthError = res.statusCode == 401 || res.statusCode == 403;
// if there is an auth error, refresh the token
// and make the request again
if (!opt_dontForceRefresh && hasAuthError && credentials.refresh_token) {
// refresh access token and re-request
that.refreshToken_(credentials.refresh_token, function(err, result) {
if (err) {
opt_callback && opt_callback(err, null, null);
} else {
var tokens = result;
tokens.refresh_token = credentials.refresh_token;
that.credentials = tokens;
that.request(opts, opt_callback, true);
}
});
}
这是我收到的错误
我正在尝试使用Google驱动器列出文件。 使用中的答案https://stackoverflow.com/a/11280257我发现了一个无法找到原因的问题。 我有这个错误: 在行中
谢了!
我为我的帐户name@steelkiwi.com(谷歌应用程序)创建了服务帐户,我的应用程序运行良好。然后我为我的个人帐户name@gmail.com创建了服务帐户,为我的应用程序使用这个新的凭据,现在当我试图插入文件时,我得到错误500和下一个文本: HttpError 500请求https://www.googleapis.com/upload/drive/v2/files时?quotause
我是第一次使用谷歌API,我在尝试下载文件对象“下载Url”属性的文件时遇到问题。我当前正在使用“服务帐户”选项以及关联的服务帐户电子邮件和 P12 证书。 但是,URL返回“https://doc-08-68-docs.googleusercontent.com/docs/securesc/bteg36c1tifegg79l2ov17og25612tet/gk7kn52ahe4d0to7d6ht