无法在Node.js中将Gmail联系人与passport-google-oauth同步

Jac*_*ack 2 node.js passport.js

我是passport.js的新手.我正在使用它进行身份验证和获取Gmail contacts,以获取我需要传递scope值的联系人https://www.google.com/m8/feeds.但是除了个人资料详细信息之外我没有得到联系人列表.

这是我的代码:

 //register with google
    app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email','https://www.google.com/m8/feeds'] }));

    // the callback after google has authenticated the user
    app.get('/auth/google/callback', passport.authenticate('google', {
            successRedirect : '/user/dashboard',
            failureRedirect : '/register.html'
        })); 
Run Code Online (Sandbox Code Playgroud)

我的passport.js代码:

    passport.use(new GoogleStrategy1({
    consumerKey: config.auth.googleAuth.clientID,
    consumerSecret: config.auth.googleAuth.clientSecret,
    callbackURL: config.auth.googleAuth.callbackURL
  },
  function(token, tokenSecret, profile, done) {
    console.log(profile);
    return done(err, user);
  }
));
Run Code Online (Sandbox Code Playgroud)

当我打印时,profile我只收到用户详细信息contact list.我不知道,我为此做了什么.任何帮助将不胜感激.

谢谢.

abd*_*rik 6

以下是用于获取的以下步骤 Gmail contacts

1-要与任何Google API进行通信,我们需要在Google控制台上创建帐户

2-之后,创建一个项目,这是我们希望与谷歌API沟通,建立项目谷歌提供后secret keyclient key它用来与谷歌沟通.每当我们的应用程序尝试与任何Google API通信时,都需要这些密钥.

3-要获取Gmail联系人,Google会提供https://www.google.com/m8/feeds/contacts/default/full?alt=json&oauth_token=xxxxxx

4-我们只需要调用此API来获取联系人,此API在通信之前需要一些凭据.

5-用户必须已使用Google登录并拥有API用于获取用户联系人的令牌.

6-通常我们更喜欢使用护照Google策略登录Google.我们的一半事情都是通过Passport.js谷歌和令牌的认证完成的.

7-当用户使用Google登录时,Passport.js扮演成功登录的中间件的角色,在此期间,护照提供当前用户的令牌.那段时间我们正在拨打联系人API https://www.google.com/m8/feeds/contacts/default/full?alt=json&oauth_token=xxxxxx

我们很容易获得令牌,而Google创建的令牌会在一小时后过期,但我们不应担心,因为护照内部提供了Google提供的新令牌.

希望它能为你效劳.


更新

让我们玩吧 REST API

通过使用获取所有联系人REST call

使用请求模块请求HTTP呼叫

request.get({
    url: 'https://www.google.com/m8/feeds/contacts/default/full',
    headers: {
        'Authorization': 'Bearer <Your access token>',
        'Content-Type': 'application/json'
    },
    qs: qs,//Optional to get limit, max results etc
    method: 'GET'
    }, function (err, response, body) {

   });
Run Code Online (Sandbox Code Playgroud)