[英]Facebook Graph API - What's the name of the array me/likes returns?
我使用 de Javascript SDK 连接到 Facebook Graph API 并检索我自己的喜欢。 我的代码在控制台中返回一个包含多个对象的 JSON 数组。 它返回的数组的名称是什么?
我需要知道这一点,以便我可以针对每个对象的特定字段并通过 JS 和 HTML 将它们显示在网页上。
我的图形 API 调用:
function getLikes() {
FB.api(
"/me/likes",
function (response) {
if (response && !response.error) {
console.log(response)
}
}
);
控制台中的 JSON 响应:
简单一:
GET /me?fields=id,name,likes
输出类似
{
"id": "372934792749234729479",
"name": "Firstname Lastname",
"likes": {
"data": [
{
"name": "Golf",
"category": "Sport",
"id": "105942022769573",
"created_time": "2015-01-01T14:45:39+0000"
}
],
"paging": {
"cursors": {
"before": "Njg0MTM5ODQyMjk=",
"after": "MTA1OTQyMDIyNzY5NTcz"
}
}
}
}
所以likes.data
就是你想要的东西。
这是一个关于如何显示喜欢的示例:
function getLikes() {
FB.api("/me/likes", function (response) {
if (response && !response.error) {
console.log(response);
response.data.forEach(function(like, index, array) {
console.log("Like " + (index+1) + ": " + like.name + " with id " + like.id);
});
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.