繁体   English   中英

如何在节点js中使用google api获取人员信息?

[英]how to get people info using google api in node js?

我想在服务器端验证用户谷歌ID。所以我想通过使用谷歌api用户谷歌信息。我已经通过所有文档,但我卡住了。我已经看到这个代码,它的工作正常:

var google = require('googleapis');
var plus = google.plus('v1');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);

// Retrieve tokens via token exchange explained above or set them:
oauth2Client.setCredentials({
  access_token: 'ACCESS TOKEN HERE',
  refresh_token: 'REFRESH TOKEN HERE'
});

plus.people.get({ userId: 'me', auth: oauth2Client }, function(err, response) {
  // handle err and response
});

但这是谷歌加。我想获取用户谷歌个人资料,ID不是谷歌加信息。 请帮忙。

对于googleapis版本19.0.0 ,你将不得不做这样的事情:

const googleapis = require('googleapis');

googleapis.people('v1').people.get({
  resourceName: 'people/me',
  personFields: 'emailAddresses,names',
  auth: oauth2Client,
  (err, response) => {
    // do your thing
  }
});

字段resourceNamepersonFields可能会因为说这些是必需的而出错。 您可以在https://developers.google.com/people/api/rest/v1/people/get找到有关这些内容的详细信息。

至于范围,以下内容对于此代码段应该足够了: https//www.googleapis.com/auth/userinfo.emailhttps://www.googleapis.com/auth/userinfo.profile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM