Instagram API:我可以检查用户是否已验证吗?

问题描述 投票:0回答:2

我想知道是否有任何方法可以使用Instagram API检查用户验证徽章?

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

谢谢!

instagram-api
2个回答
7
投票

好吧,这不是一个很好的答案,但这就是我完成同样任务的方法。一旦我从 API 获得了用户名,我就会在其个人资料页面的源代码中执行以下正则表达式:

$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

我们还添加了一项额外的检查,如果元内容标签中包含“官方帐户”,那么我们就假设它是官方的。 (示例:https://instagram.com/3doorsdown)我们添加此检查是因为 Instagram 在 2014 年开始进行验证帐户,并且有相当多的名人尚未获得验证徽章。它应该能收集到一些信息,但也很可能带来误报。

注意:如果 Instagram 更改其页面上的 JSON 结构或元标记,此解决方案将会失效,因此使用风险需您自担。我们只需要一个脚本来检查少量用户名以获取经过验证的徽章,我很快就想出了这个方法。最好的解决方案是每当他们更新 API 时。


0
投票

enter image description here

[1]:https://i.stack.imgur.com/1aqpO.jpg
© www.soinside.com 2019 - 2024. All rights reserved.