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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.