使用PHP从Instagram获取基本信息 [英] Getting basic information from Instagram using PHP

查看:215
本文介绍了使用PHP从Instagram获取基本信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$url = 'https://api.instagram.com/v1/users/XXXX?access_token=XXXX';
echo json_decode(file_get_contents($url))->{'followed_by'};

我正在使用此代码,但我不明白问题所在.我是PHP新手,所以请原谅新手错误.我正在尝试让"followed_by"自行显示.我设法让Facebook的喜欢"和Twitter的关注者以这种方式显示.

I am using this code and I do not understand what the issue is. I'm new to PHP so excuse the newbie mistake. I'm trying to get the "followed_by" to display on its own. I've managed to get Facebook's "like" and twitter's followers to display this way.

推荐答案

如果您需要在不登录的情况下获取关注者人数(或其他字段),Instagram很好用,可以将其放入页面源中的JSON中:

In case you need to grab follower count (or other fields) without logging in, Instagram is nice enough to put them in JSON inside the page source:

$raw = file_get_contents('https://www.instagram.com/USERNAME'); //replace with user
preg_match('/\"edge_followed_by\"\:\s?\{\"count\"\:\s?([0-9]+)/',$raw,$m);
print intval($m[1]);

//returns "123"

希望有帮助.

2016年5月24日,已更新为更宽容JSON中的空格.

24 May 2016 Updated to be more tolerant of spaces in JSON.

2018年4月19日已更新为使用新的"edge_"前缀.

19 Apr 2018 Updated to use new "edge_" prefix.

这篇关于使用PHP从Instagram获取基本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆