简体   繁体   English

如何从instagram api响应中获取“数据”?

[英]How do I get the “data” from instagram api response?

I'm getting this kind of response from instagram server. 我从instagram服务器收到这种回应。

{
    "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: 我试图在PHP中进行json解码,例如:

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

but $userfeed and $tried_this seems to be the same. 但是$userfeed$tried_this似乎相同。

UPDATE Down below is the REAL data... UPDATE下面是REAL数据...

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\&max_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 shar {“ pagination”:{“ next_url”:“ https://api.instagram.com/v1/users/3/media/recent?access_token=blablabla\&max_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“ :“您能给我喊一声吗?”,“来自”:{“用户名”:“ nick_putukian1”,“ profile_picture”:“ http://images.ak.instagram.com/profiles/profile_1370615750_75sq_1401835573.jpg”,“ id “:” 1370615750“,”全名“:”尼古拉斯·普图克安“”,“ id”:“ 734973811849433422”},{“ created_time”:“ 1401836165”,“ text”:“我只有一​​个关注者”,“来自”: {“ 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”:“亲爱的@kevin您可以加shar吗 e feature on IG? 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":"\?\?\?\?\?\?\?\\udc9\u003c/i> 谢谢。“,”来自“:{”用户名“:” 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”,“文本”:“ \\ 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. 请原谅我没有给您提供“可读的” var_dump,但是由于某种原因,我正在尝试的特定服务器上的var_dump无法使其达到预期的可读性。

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

is returning NULL 返回NULL

Assuming, a valid JSON string, you would do: 假设一个有效的JSON字符串,您将执行以下操作:

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

Lets assume that you have provided access_token, than following syntax will meet your requirements 假设您提供了access_token,那么以下语法将满足您的要求

$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']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM