【问题标题】:Instagram is_private regex [closed]Instagram is_private 正则表达式 [关闭]
【发布时间】:2018-11-09 18:27:31
【问题描述】:

我想检查用户在 Instagram 上是否为私人用户。在网上搜索时发现:Getting basic information from Instagram using PHP

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

它使用正则表达式来检查用户的关注者数量。
现在我正在尝试使用正则表达式来检查用户是否为私人用户,但我无法弄清楚。该字段在 JSON 响应中声明为 is_private,但我无法使其正常工作。

这是正确的做法吗?

【问题讨论】:

  • 您真的希望我们注册 Instagram 只是为了了解其中的区别吗?
  • 这是JSON,所以请使用json_loads()等适当的函数

标签: php regex instagram


【解决方案1】:

你不想用 Regex 来做这件事,而是检查网页

$instagramPage = strip_tags(file_get_contents('http://instagram.com/Username'));
if (strpos($instagramPage,'"is_private":true') !== false) {
    return 'Account is private';
} else {
    return 'Account is public';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-08
    • 2017-11-13
    • 2015-04-27
    • 1970-01-01
    • 2016-09-28
    • 2015-10-22
    • 1970-01-01
    相关资源
    最近更新 更多