Express 检索Google+;用户的活动列表
我需要获得Google+中用户的活动列表。我的编码平台是node.js Express framework,我使用的是google api nodejs客户端包Express 检索Google+;用户的活动列表,express,google-api,google-plus,google-api-nodejs-client,Express,Google Api,Google Plus,Google Api Nodejs Client,我需要获得Google+中用户的活动列表。我的编码平台是node.js Express framework,我使用的是google api nodejs客户端包 var googleapis = require('googleapis'); var auth = new googleapis.OAuth2Client(); var accessToken="XXXXXX......"; googleapis .discover('plus', 'v1') .execute(fun
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对象的值找到了它
错误----------------->
我认为问题在于,您正在为
client.plus.activities.list()
指定一个空字段参数,而不是根本不提供字段参数。这告诉它不返回结果字段。由于fields参数是可选的,因此可以完全忽略它
尝试以下方法:
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
})
如果您提供
err
对象的值会有所帮助,但这里有一些想法:
- (了解你的基本个人资料信息和你圈子里的人的名单)
- (知道你在谷歌上是谁)
- (查看您的电子邮件地址)
- (查看有关您帐户的基本信息)
{}
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
}, {}) // <--- see the extra {} here!
.withAuthClient(auth)
.execute(function (err, response) {
console.log('activities---------------------->', response.items);
});
客户端
.plus.activities.list({
userId:'我',
收藏:'公众',
最大结果:100
},{}//我把它改成了你的答案。但仍然没有结果。特别是在这样调试时,您还应该查看“err”中返回的内容。检查一下,并把它作为问题的一部分。你是对的。原因是你在第二点中提到的范围。正如你所说的,我记录了错误值。我只得到我添加的公开帖子。如何获得他人的公开职位?
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
}, {}) // <--- see the extra {} here!
.withAuthClient(auth)
.execute(function (err, response) {
console.log('activities---------------------->', response.items);
});