这是请求权限并尝试列出圈子的源代码, 我想要的是能够列出圈子的人,添加/删除圈子中的人,但是当我尝试这样做时我得到一个禁止的错误,并且我可以访问这些范围。
var express, router, nconf, OAuth2, oauth2Client, scopes, google;
scopes = [
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/plus.circles.read',
'https://www.googleapis.com/auth/plus.circles.write'
];
google = require('googleapis')
nconf = require('nconf');
OAuth2 = google.auth.OAuth2;
express = require('express');
router = express.Router();
oauth2Client = new OAuth2(CLIENT_ID, SECRET_ID, REDIRECT_URL);
router.get('/', function(req, res) {
var url = oauth2Client.generateAuthUrl({
access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
scope: scopes // If you only need one scope you can pass it as string
});
res.redirect(url);
});
router.get('/auth', function(req, res) {
console.log("code >> " + req.query.code);
oauth2Client.getToken(req.query.code, function(err, tokens) {
if(!err) {
console.log("TOKENS >> " + JSON.stringify(tokens));
oauth2Client.setCredentials(tokens);
var plusDomains = google.plusDomains('v1');
plusDomains.circles.list({ userId: 'me', auth: oauth2Client }, function(err, circles) {
console.log('Result circles: ' + (err ? err.message : JSON.stringify(circles)));
});
}
res.send({tokens: tokens});
});
});
module.exports = router;