我需要在 Google+ 中获取用户的活动列表。我的编码平台是 node.js Express 框架,我使用的是 google-api-nodejs-client 包。
var googleapis = require('googleapis');
var auth = new googleapis.OAuth2Client();
var accessToken="XXXXXX......";
googleapis
.discover('plus', 'v1')
.execute(function (err, client) {
if (err) {
console.log('Problem during the client discovery.', err);
return;
}
auth.setCredentials({
access_token: accessToken
});
client
.plus.people.get({ userId: 'me' })
.withAuthClient(auth)
.execute(function (err, response) {
console.log('My profile details------>', response);
});
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
})
.withAuthClient(auth)
.execute(function (err, response) {
console.log('err----------------------------->',err);//EDIT
console.log('activities---------------------->', response.items);
});
});
我得到了我的个人资料详细信息。但是活动正在返回值:null
。我检查了我的 Google+ 页面以确保我有公开的帖子。另外,我自己也向“公众”分享了一些帖子。请帮我找到我的代码中的错误。
编辑
实际上,有一个错误。我按照 Ryan Seys 的建议通过在控制台中记录 err 对象的值来找到它。
错误--------------->
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}