Jump to content

Accessing Value from JSON API Instagram


cutez7boyz

Recommended Posts

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

...
Link to comment
https://forums.phpfreaks.com/topic/285276-accessing-value-from-json-api-instagram/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.