我正在尝试导入gmail联系人.我已成功获取access_token,但在尝试获取联系人浏览器时不断抛出错误.invalid_grant
我的代码如下.
用于身份验证和回调.
authorize: function(req, res){
var CLIENT_ID = '927112080821-vhsphqc79tb5ohfgpuvrp8uhh357mhad.apps.googleusercontent.com';
var CLIENT_SECRET = 'gdgofL0RfAXX0in5JEiQiPW8';
var SCOPE = 'https://www.google.com/m8/feeds';
oa = new oauth.OAuth2(CLIENT_ID,
CLIENT_SECRET,
"https://accounts.google.com/o",
"/oauth2/auth",
"/oauth2/token");
res.redirect(oa.getAuthorizeUrl({scope:SCOPE, response_type:'code', redirect_uri:'http://localhost:1234/callback'}));
},
callback: function(req, res){
console.log(req.query.code);
oa.getOAuthAccessToken(req.query.code, {grant_type:'authorization_code', redirect_uri:'http://localhost:1234/callback'}, function(err, access_token, refresh_token) {
if (err) {
res.end('error: ' + JSON.stringify(err));
} else {
getContactsFromGoogleApi(access_token);
//res.write('access token: ' + access_token + '\n');
//res.write('refresh token: ' + refresh_token);
//res.end();
}
});
},
Run Code Online (Sandbox Code Playgroud)
用于导入联系人
function getContactsFromGoogleApi (access_token, req, res, next) {
console.log('access_token ' + access_token); …
Run Code Online (Sandbox Code Playgroud) 我有以下函数写在server.js我一直得到 error: uncaughtException: Cannot call method 'redirect' of undefined
function(req, res) {
async.waterfall([
function(next){
next(null, res);
},
function(next){
next(null, res);
},
function(next, res){
res.redirect('www.google.com')
}
]);
}
Run Code Online (Sandbox Code Playgroud)
从以下答案进行上述更改后我得到了,错误如下:
2014-09-04T13:56:08.678Z - error: uncaughtException: Object function (err) {
if (err) {
callback.apply(null, arguments);
callback = function () {};
}
else {
var args = Array.prototype.slice.call(arguments, 1);
var next = iterator.next();
if (next) {
args.push(wrapIterator(next));
}
else {
args.push(callback);
}
async.nextTick(function () {
iterator.apply(null, args);
});
}
} has no method 'send'
Run Code Online (Sandbox Code Playgroud)