dswqw66280 2016-08-20 14:39
浏览 57
已采纳

将Instagram json数据解析为php中的可用变量

I have a working api call to get basic user info and I am trying to return just the "followed_by" portion of the json data from "counts". This link should return just the json page on your browser

https://api.instagram.com/v1/users/self/?access_token=3514554632.a691e29.3f773f5f335a4ba98fc9609d1d405fb0

And here is my code to try and parse the result, but all I am getting is a blank screen.

$jsondata = file_get_contents("https://api.instagram.com/v1/users/self/?access_token=3514554632.a691e29.3f773f5f335a4ba98fc9609d1d405fb0");
$json = json_decode($jsondata, true);
$json2 = json_decode($jsondata);
//method one to parse, not working
$parsedvalue = $json['counts'][1]['followed_by'];
echo $parsedvalue;

//method two to parse, not working
$followercount = $json2->counts->followed_by;
echo $followercount;
  • 写回答

1条回答 默认 最新

  • douyou4819 2016-08-20 15:25
    关注

    Here is the fix I got figured out for //method 2

    $jsondata = file_get_contents("https://api.instagram.com/v1/users/self/?access_token=3514554632.a691e29.3f773f5f335a4ba98fc9609d1d405fb0");
    $json2 = json_decode($jsondata);
    
    $followercount = $json2->data->counts->followed_by;
    

    This properly returns your follower count, but I still need help understanding how to fix method one

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部