gpt4 book ai didi

javascript - 如何合并两个 facebook graph api 数据结果(JSON)

转载 作者:行者123 更新时间:2023-12-03 10:01:16 25 4
gpt4 key购买 nike

由于 facebook 图表只能返回 100 个用户点赞 ("/me/likes?limit=100"),我创建了一个循环,不断重复,直到加载所有点赞。因此,我有一个单独的图形 api 结果对象,循环完成后我需要将它们合并为一个。下面是一个包含两个 Facebook 回复的简短数组

var responses = [
{
"data":[
{
"category":"Community",
"name":"Uxcamp.pl",
"id":"1401334970104742",
"created_time":"2015-05-28T12:05:13+0000"
},
{
"category":"Musician/Band",
"name":"The Shins",
"id":"129599657069433",
"created_time":"2015-05-21T15:59:10+0000"
}
],
"paging":{
"cursors":{
"before":"MTQwMTMzNDk3MDEwNDc0Mg==",
"after":"MTI5NTk5NjU3MDY5NDMz"
},
"next":"https://graph.facebook.com/v2.3/999625400069239/likes?access_token=CAAKvGzm…i7RfCs4rI5yqCsUxKJA87vpgMiYo8IYku59uHt&limit=2&after=MTI5NTk5NjU3MDY5NDMz"
}
},
{
"data":[
{
"category":"Other category",
"name":"Other event",
"id":"2342340104742",
"created_time":"2015-02-28T12:05:13+0000"
},
{
"category":"Musician/Band",
"name":"Rammstein",
"id":"129543547069433",
"created_time":"2015-03-21T15:59:10+0000"
}
],
"paging":{
"cursors":{
"before":"MTQwMTMzNDk3MDEwNDc0Mg==",
"after":"MTI5NTk5NjU3MDY5NDMz"
},
"next":"https://graph.facebook.com/v2.3/34095843095874309438/likes?access_token=CAAKvGzm…i7RfCsIOSIOS(o8IYku59uHt&limit=2&after=MTI5NTk5NjU3MDY5NDMz"
}
}
];

// function...
// response = mergeAll(response);

最佳答案

尝试

var likes = [];

responses.forEach(function(response, index, array) {
likes = likes.concat(response.data);
});

console.log(JSON.stringify(likes));

这应该给你

[
{
"category": "Community",
"name": "Uxcamp.pl",
"id": "1401334970104742",
"created_time": "2015-05-28T12:05:13+0000"
},
{
"category": "Musician/Band",
"name": "The Shins",
"id": "129599657069433",
"created_time": "2015-05-21T15:59:10+0000"
},
{
"category": "Other category",
"name": "Other event",
"id": "2342340104742",
"created_time": "2015-02-28T12:05:13+0000"
},
{
"category": "Musician/Band",
"name": "Rammstein",
"id": "129543547069433",
"created_time": "2015-03-21T15:59:10+0000"
}
]

结果。

查看

http://jsfiddle.net/4wqw23qc/

关于javascript - 如何合并两个 facebook graph api 数据结果(JSON),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com