dswqw66280 2016-08-20 22: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 23: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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?