使用访问令牌在节点中获取Google +用户个人资料

我正在尝试在Node中获取用户configuration文件的详细信息。

stream程是这样的,我有一个移动应用程序,为我生成令牌(通过谷歌加本地SDKauthentication),然后我把令牌发送到我的节点服务器,我想从谷歌获得有关用户的详细信息。 我尝试了以下(假设我有从客户端access_token ):

 var request = require('request'); request('https://www.googleapis.com/oauth2/v2/userinfo?access_token=' + access_token, function(err, res, body) { if (err) return callback(err); if (res.statusCode != 200) { return callback(new Error('Invalid access token: ' + body)); } else { var me; try { me = JSON.parse(body);} catch (e) { return callback(new Error('Unable to parse user data: ' + e.toString())); } console.log('user profile:', me); } }); 

这工作,但有时我得到像null displayName字段,空email (即使我有范围)的不良反应,它是不可靠的整体。

我曾尝试使用Google API Node模块,但是那里的stream程假定我需要获取令牌并且不必要的复杂。

除此之外,我不明白谷歌的API版本之间的差异,不知道什么时候使用什么。

编辑

看来只有通过iOS SDK生成的令牌才会出现null displayName字段的问题。 使用Android SDK生成的令牌没有问题,调用API可以在displayNameparsing。 我尝试了iOS令牌并调用以下API:

 https://www.googleapis.com/plus/v1/people/me?access_token=... 

我在结果中得到了一个displayName ,但是在从我的服务器接到几个呼叫之后,我得到了

 { "error": { "errors": [ { "domain": "usageLimits", "reason": "dailyLimitExceededUnreg", "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", "extendedHelp": "https://code.google.com/apis/console" } ], "code": 403, "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." } } 

问题被隔离到我的IOS用户生成的令牌。

看来我通过IOS SDK得到的令牌与我在我的问题( https://www.googleapis.com/oauth2/v2/userinfo )中提到的API调用不兼容。 上述调用可以使Android SDK生成的令牌运行良好。

所以要find一个共同点,我不得不从我的服务器使用以下API调用:

 https://www.googleapis.com/plus/v1/people/me?access_token=... 

你应该得到一个类似这样的对象(省略个人领域):

 { kind:"plus#person", etag:"...", gender:"male", emails:[ { value:"...", type:"account" } ], urls:[ { value:"...", label:"Buzz" } ], objectType:"person", id:"...", displayName:"...", name:{ familyName:"...", givenName:"..." }, url:"...", image:{ url:"..." }, isPlusUser:true, language:"en", ageRange:{ min:21 }, verified:false, cover:{ layout:"banner", coverPhoto:{ url:"...", height:626, width:940 }, coverInfo:{ topImageOffset:0, leftImageOffset:0 } } }