Instagram API:我可以检查用户是否已通过验证? [英] Instagram API: Can i check if user is verified?

查看:118
本文介绍了Instagram API:我可以检查用户是否已通过验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以通过Instagram API检查用户验证徽章吗?

I would like to know if there is any way to check if the user verification badge with the Instagram API?

我已经看到 https://api.instagram.com/v1/users/ {user-id }如果用户通过了验证,则不会返回,但是如果查看用户页面的源代码,则可以看到它具有一个名为isVerified key的布尔值,并且该值在用户的json结构中.

I have saw that https://api.instagram.com/v1/users/{user-id} doesn't returns if the user is verified, but if you view the source code of a users page, you can see that it has a boolean that called isVerified key and it's value inside a json struct of the user.

谢谢!

推荐答案

好的,这不是一个很好的答案,但这是我完成相同任务的方式.从API获得用户名后,请在其个人资料页面的源代码上执行以下正则表达式:

Ok, this is not a great answer but here is how I accomplished this same task. Once I have a username from the API I do the following regex on the source of their profile page:

$response = file_get_contents('https://instagram.com/'.$username);
if (preg_match('/"user":\{"username":"'.$username.'",.*?"isVerified":true\},"__path":".*?'.$username.'.*?"/s', $response) || preg_match('/<meta content=".*?official.*?account.*?" name="description" \/>/is', $response)) {
    print "VERIFIED USER!";
}

正如我之前所说,这是超级hacky,但该API当前未提供isVerified值.在他们这样做之前,我将使用此正则表达式.它会在您引用的JSON结构中查找"isVerified":true部分. (例如: https://instagram.com/taylorswift )

As I said before this is super hacky but the API currently doesn't provide an isVerified value. Until they do I am using this regular expression. It looks for "isVerified":true part of the JSON struct you referenced. (example: https://instagram.com/taylorswift)

我们还添加了另一项检查,在该检查中,如果meta内容标签中包含正式帐户",则我们假定它是正式的. (示例: https://instagram.com/3doorsdown )我们添加了此检查,因为Instagram于2014年开始使用经过验证的帐户并且还有很多尚未获得经过验证的徽章的名人.它应该处理一些问题,但也很可能带来误报.

We also added an additional check where if the meta content tag has "official account" in it then we assume it's official. (example: https://instagram.com/3doorsdown) We added this check because Instagram started doing verified accounts in 2014 and there are quite a few celebrities that haven't gotten a verified badge yet. It should pick up some of the pieces but could very well bring in false positives too.

注意:如果Instagram更改了其页面上的JSON结构或元标记,则此解决方案将失效,因此后果自负.我们只需要一个脚本来检查少量用户名中是否有经过验证的徽章,我便想到了这种快速的方法.最好的解决方案是每当他们更新API时.

NOTE: This solution will break if Instagram ever changes the JSON struct or meta tags on their pages so use at your own risk. We only needed a script to check a small amount of usernames for verified badges and I came up with this real quick. The best solution will be whenever they update their API.

这篇关于Instagram API:我可以检查用户是否已通过验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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