如何使用instagram API?
问题描述:
我开始使用Instagram API。我想从一个标签中获取所有照片。 为此,我用这样的API链接:如何使用instagram 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
并发送下一个回应此字段。这是正确的?
答
使用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);