cutez7boyz Posted January 11, 2014 Share Posted January 11, 2014 I'm trying to accessing value from json api instagram. I've successed to access simple api that returns like this: { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } Since im trying to tricky the API to get all user media in one account, i combine API and next pagination api in one file named cache.json. Now it looks like this: { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } How to accessing that value in PHP? There are three data value either when the simple api just one data value. Im using this code to accessing that value but doesn't worked: $cache = './cache.json'; $response = json_decode(file_get_contents($cache),true); //Decode as an json array if(is_array($response['data'])){ foreach ($response['data'] as $data) { if ($data['comments']['data'] != null) { foreach($data['comments']['data'] as $comment){ ... Quote Link to comment https://forums.phpfreaks.com/topic/285276-accessing-value-from-json-api-instagram/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.