我正在与facebook合作,我正在尝试将来自群组帖子的部分信息与发布到该群组的用户的名称和用户ID相结合。这是我的代码:
var theGroup = component.get('v.feedAPI');
var theToken;
var lastTime = component.get('v.feedScraped');;
lastTime = lastTime.replace(" ", "T");
var nameAndMessage = {};
nameAndMessage['posts'] = [];
FB.login(function(response) {
if (response.authResponse) {
theToken = response.authResponse.accessToken;
FB.api('/' + theGroup + '/feed?access_token=' + theToken, 'GET', {
"fields": "message,updated_time,id,type",
"since": lastTime.toString()
},
function(response1) {
var i = 0;
var len = response1.data.length;
for (var i = 0; i < len; i++) {
var ii = 0;
FB.api('/' + response1.data[i].id, 'GET', {
"fields": "from,id,message"
},
function (response) {
var theKey = 'post' + ii;
nameAndMessage["posts"][Number(ii)] = {};
nameAndMessage["posts"][Number(ii)]["uName"] = response.from.name;
nameAndMessage["posts"][Number(ii)]["uId"] = response.from.id;
nameAndMessage["posts"][Number(ii)]["thePost"] = response1.data[ii].message;
nameAndMessage["posts"][Number(ii)]["createdT"] = response1.data[ii].updated_time;
nameAndMessage["posts"][Number(ii)]["postID"] = response1.data[ii].id;
ii++;
}
);
}
}
);
console.log(nameAndMessage);
var convertString = JSON.stringify(nameAndMessage);
console.log(convertString);
} else {
alert('User cancelled login or did not fully authorize.');
}
}, {
scope: 'user_managed_groups',
return_scopes: true
});
我的stringify生成的字符串是:
{ “职位”:[]}
“nameAndMessage”的实际结果产生了25条记录,但显示如下:
{posts:Array(0)} 帖子 : 阵列(25)