2020年instagram api变更后,如何从instagram公众号获取instagram粉丝数?

Hyu*_*Cho 16 instagram instagram-api

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

我还查看了 instagram basic display/graph 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 -> 无法获取关注者数量
  • 图 api -> 无法访问消费者帐户

有没有人对此有解决方案?

谢谢!

Dye*_*517 17

有同样的问题。我最终检查了 Instagram 网络并发现了这一点:

https://i.instagram.com/api/v1/users/web_profile_info/?username=<USERNAME>.
Run Code Online (Sandbox Code Playgroud)

确保user-agent在请求中添加具有以下值的标头:

Instagram 76.0.0.15.395 Android (24/7.0; 640dpi; 1440x2560; samsung; SM-G930F; herolte; samsungexynos8890; en_US; 138226743)
Run Code Online (Sandbox Code Playgroud)

你可以得到追随者的计数data.user.edge_followed_by.count


小智 5

您可以使用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
Run Code Online (Sandbox Code Playgroud)