2017-10-18 188 views
0

我開始使用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併發送下一個迴應此字段。這是正確的?

回答

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);