如何获得谷歌+用户configuration文件的细节,给出访问令牌和刷新令牌

使用谷歌API

function googleLogin(req, res, next) { var google = require('googleapis'); var plus = google.plus('v1'); SCOPES = 'https://mail.google.com'; var OAuth2 = google.auth.OAuth2; var oauth2Client = new OAuth2( '215995260545-6rp2pg69olionsiugudcl4fni3o36ap9.apps.googleusercontent.com', 'xxxxxxxxxxxxxxxxxxxxxxxx', 'https://developers.google.com/oauthplayground' ); oauth2Client.setCredentials({ access_token: req.query.ac_token, refresh_token: req.query.rf_token }); plus.people.get({ userId: 'me', auth: oauth2Client }, function(err, response) { if (err) console.log(err); console.log(response); }); } 

当我运行这个代码时,我得到**insufficient permission**的错误。 我错了吗?

  "code": 403, "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" } ] 

我怎么解决这个问题?? 我也提到了Gmail的API范围。

       

网上收集的解决方案 "如何获得谷歌+用户configuration文件的细节,给出访问令牌和刷新令牌"

问题的主要部分是您使用了错误的端点https://developers.google.com/oauthplayground不是您可以使用的知识

你应该怎么做

尝试添加以下范围

个人资料 – 查看您的基本资料信息

你也不应该去,虽然谷歌+ API你可能能够请求从用户信息端点的信息,但这取决于你是什么信息后

https://www.googleapis.com/oauth2/v3/userinfo?access_token=XXX

UserInfo响应

 { "family_name": "Lawton", "name": "Linda Lawton", "picture": "http://img.nodejscore.com/google-api/photo.jpg", "locale": "en", "gender": "female", "link": "https://plus.google.com/+LindaLawton", "given_name": "Linda", "id": "117200475532672775346" } 

人们api请求

 https://www.googleapis.com/plus/v1/people/me 

响应

 { "braggingRights": "Extreme Beekeeper first to recorded an Hive inspection using Google Glass with out a veil on.", "image": { "url": "http://img.nodejscore.com/google-api/photo.jpg?sz=50", "isDefault": false }, "id": "117200475532672775346", "objectType": "person", "verified": false, "tagline": "Google Developer Expert 2014 - 2017", "etag": "\"ucaTEV-ZanNH5M3SCxYRM0QRw2Y/0gZZ-LRb-PWLjbw12lr-IOAearE\"", "circledByCount": 2514, "occupation": "Google Developer Expert, BIA Developer at Targit", ..... Lots of stuff here ... } 

你应该尝试使用Oauth游乐场