bestprogrammerintheworld
bestprogrammerintheworld

Reputation: 5520

How do I get the "data" from instagram api response?

I'm getting this kind of response from instagram server.

{
    "meta": {
        "code": 200
    },
    "data": {
        ...
    },
    "pagination": {
        "next_url": "...",
        "next_max_id": "13872296"
    }
}

How do I get the "data" - part? I've tried to json decoding in PHP like:

//$userfeed is giving me something like above.
$tried_this = json_decode($userfeed['meta']);

but $userfeed and $tried_this seems to be the same.

UPDATE Down below is the REAL data...

I've left out the access token, but otherwise it's correct. This is just a part of it, but I hope you get the picture....

{"pagination":{"next_url":"https://api.instagram.com/v1/users/3/media/recent?access_token=blablabla\u0026max_id=622063574553989866_3","next_max_id":"622063574553989866_3"},"meta":{"code":200},"data":[{"attribution":null,"tags":[],"type":"image","location":{"latitude":21.367158921,"name":"Pali Lookout","longitude":-157.79304912,"id":60507},"comments":{"count":313,"data":[{"created_time":"1401835727","text":"Can you give me a shout out","from":{"username":"nick_putukian1","profile_picture":"http://images.ak.instagram.com/profiles/profile_1370615750_75sq_1401835573.jpg","id":"1370615750","full_name":"Nicholas Putukian"},"id":"734973811849433422"},{"created_time":"1401836165","text":"I only have one follower","from":{"username":"nick_putukian1","profile_picture":"http://images.ak.instagram.com/profiles/profile_1370615750_75sq_1401835573.jpg","id":"1370615750","full_name":"Nicholas Putukian"},"id":"734977485287985692"},{"created_time":"1401837312","text":"Dear @kevin could u please add share feature on IG? So users don't have to screenshoot a foto first if we want to share it. Thanks.","from":{"username":"natalia.igaa","profile_picture":"http://images.ak.instagram.com/profiles/profile_1003500786_75sq_1401603184.jpg","id":"1003500786","full_name":"Ayu Natalia"},"id":"734987110351638699"},{"created_time":"1401837882","text":"HI KEVIN","from":{"username":"gildathegriffon","profile_picture":"http://images.ak.instagram.com/profiles/profile_320785380_75sq_1401742420.jpg","id":"320785380","full_name":"Doivid"},"id":"734991884560110057"},{"created_time":"1401838561","text":"\ud83d\ude02\ud83d\ude02\ud83c\udf42\ud83d\udc9

Forgive me for not giving you a "readable" var_dump, but for some reason the var_dump on a specific server I'm trying on doesn't make it readable as expected.

$data = json_decode($userfeed, true);
var_dump($data['data']);

is returning NULL

Upvotes: 0

Views: 3452

Answers (2)

Waqas Ikram
Waqas Ikram

Reputation: 86

Lets assume that you have provided access_token, than following syntax will meet your requirements

$url          =   "https://api.instagram.com/v1/users/3/media/recent/?access_token=ACCESS-TOKEN";
$content      =   file_get_contents($url);
$data         =   json_decode($content, true);
var_dump($data['data']);

Upvotes: 0

Ryan
Ryan

Reputation: 14659

Assuming, a valid JSON string, you would do:

$data = json_decode($json_string, true);
var_dump($data['data']);

Upvotes: 2

Related Questions