我开始使用Instagram API。我想从一个标签中获取所有照片。 为此我使用这样的api链接:
http.api.instagram.com/v1/tags/test/media/recent&access_token=...
结果我在JSON中有这样的回应:
{
"pagination": {
"next_min_id": "AQDPw33Vz6ZgxgHuZ8umA1c_Xavrys6Vuj61KqoUvr54ADSI7LKvBcx_MecQgyvaR-JrhO_s5DUAgkjFzHrGLidBZPUhxU4zi6iaNA1UeWQJVA",
"min_tag_id": "AQDPw33Vz6ZgxgHuZ8umA1c_XavryJ6Vuj61KqoasdADSI7LKvBcx_MecQgyvaR-JrhO_s5DUAgkjFzHrGLidBZPzxcU4zi6iaNA1UeWQJVA",
"deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead"
},
"data": [
{
"id": "1626816542803445150_32412343357",
"user": {
"id": "3241233357",
"full_name": "test",
"profile_picture": "https:\/\/scontent.cdninstagram.com\/t51.2885-19\/s150x150\/1626816542803445150_32412343357_a.jpg",
"username": "test_software"
},
"images": {
"thumbnail": {
"width": 150,
"height": 150,
"url": "https:\/\/scontent.cdninstagram.com\/t51.2885-15\/s150x150\/e35\/1626816542803445150_32412343357.jpg"
},
"low_resolution": {
"width": 320,
"height": 320,
"url": "https:\/\/scontent.cdninstagram.com\/t51.2885-15\/s320x320\/e35\/1626816542803445150_32412343357.jpg"
},
"standard_resolution": {
"width": 640,
"height": 640,
"url": "https:\/\/scontent.cdninstagram.com\/t51.2885-15\/s640x640\/sh0.08\/e35\/1626816542803445150_32412343357.jpg"
}
},
"created_time": "141151666",
"caption": {
"id": "17879771646166136",
"text": "#test",
"created_time": "1508666666",
"from": {
"id": "3249481157",
"full_name": "test",
"profile_picture": "https:\/\/scontent.cdninstagram.com\/t51.2885-19\/s150x150\/1626816542803445150_32412343357.jpg",
"username": "test_software"
}
},
"user_has_liked": false,
"likes": {
"count": 1
},
"tags": [
"test"
],
"filter": "Moon",
"comments": {
"count": 0
},
"type": "image",
"link": "https:\/\/www.instagram.com\/p\/BaTn124h0We\/",
"location": null,
"attribution": null,
"users_in_photo": [
]
},
....
],
"meta": {
"code": 200
}
}
如何正确解析所有数据?
Instagram获得JSON每页15个帖子。
如何解析当前的15个帖子后接下来的15个帖子?
如果我理解,我必须解析字段next_mid_id
并使用此字段发送下一个响应。这是对的吗?
答案 0 :(得分:1)
使用file_get_contents()检索Feed的内容,然后使用json_decode()将Feed中返回的字符串转换为对象。
$json_source = file_get_contents('http.api.instagram.com/v1/tags/test...');
$json_data = json_decode($json_source);
var_dump($json_data);