【问题标题】:How to get instagram follower count from instagram public account after 2020 instagram api change?2020年instagram api变更后如何从instagram公众号获取instagram粉丝数?
【发布时间】:2020-12-21 21:16:27
【问题描述】:

我试图仅使用用户的 instagram 句柄(又名@myusername)来检索关注者数量。我阅读了几个答案,您可以访问“https://www.instagram.com/{username}/?__a=1”来检索包含所有详细信息的 json 块。但是,当我在 2020 年更改 api 后尝试这样做时,url 只是将我重定向到登录页面。

我还查看了 instagram 基本显示/图形 api,但我似乎无法找到获取其他用户关注者数量的方法。

来自官方ig基本显示api文档:https://developers.facebook.com/docs/instagram-basic-display-api/reference/user
此 api 仅允许您获取 account_type、id、ig_id(即将弃用)、媒体计数和用户名。 (没有追随者数量的迹象)

来自官方 ig graph api 文档: https://developers.facebook.com/docs/instagram-api
“该 API 无法访问 Intagram 消费者帐户(即非商业或非创作者 Instagram 帐户)。如果您正在为消费者用户构建应用程序,请改用 Instagram 基本显示 API。”

由于我的程序假设从不一定专业的帐户中检索关注者数量,我似乎无法弄清楚该怎么做...

总结:

  • 我已经尝试过网页抓取 -> 被重定向到登录页面
  • 基本展示 api -> 无法获取关注者数量
  • Graph api -> 无法访问消费者帐户

有人对此有解决方案吗?

谢谢!

【问题讨论】:

  • @Hyunk 你有解决办法吗?
  • 嘿@hyun-seok-cho 你找到解决方案了吗?
  • 有人找到解决方案了吗?

标签: instagram instagram-api


【解决方案1】:

您可以使用Instaloader Python 模块。 这是一个简单的例子:

import instaloader
L = instaloader.Instaloader()
user = "IG_USERNAME"
password = "IG_PASSWORD"
L.login(user, password)
profile = instaloader.Profile.from_username(L.context, user)

print(profile.followees) #number of following
print(profile.followers) #number of followers
print(profile.full_name) #full name
print(profile.biography) #bio
print(profile.profile_pic_url)  #profile picture url 
print(profile.get_posts()) #list of posts
print(profile.get_followers()) #list of followers
print(profile.get_followees()) #list of followees

【讨论】:

    【解决方案2】:

    Instagram 阻止了您的 IP ...您需要使用未被检测到的代理从 Instagram 抓取该 IP,通常,住宅 IP 已通过。

    向 IG API 端发送 HTTP 请求 > 如果得到 JSON 响应,则表示良好且未检测到,否则检测到代理,不适合 Instagram。

    代码(在 c# 中,但在 python 中可以遵循相同的逻辑):

    var httpClientHandler = new HttpClientHandler()
                {
                    Proxy = new WebProxy("127.0.0.1:8080", false),
                    UseProxy = true
                };
    
                var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);
                var response = await client.GetAsync("https://www.instagram.com/instagram/?__a=1");
    
            
                if ( response.Content.Headers.ContentType.MediaType == "application/json")
                {
                    // Not detected proxy and good for Instagram
    
                }
                else
                {
                   // Detected proxy and not good for Instagram
                }
    

    如果您问为什么 Instagram 会屏蔽某些 IP?只是 Instagram 有一个庞大的数据库,其中包含过去发送超过允许的限制请求的 IP ......他们这样做是为了防止抓取。

    【讨论】:

    • 谢谢,我会尽力将结果回复您!
    • 使用 fiddler 或类似的工具来捕捉带有状态码的 HTTP 响应,看看他们是否还在阻止你的 IP...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多