Skip to main content
 首页 » 编程设计

python之试图在 Instagram API 中查找关注者数量

2025年05月04日13xing901022

我正在寻找特定用户的关注者数量,就像您使用 Instagram API 控制台时获得的那样:

from instagram.client import InstagramAPI 
access_token = "Access Token" 
api = InstagramAPI(access_token=access_token) 
user_info = api.user(user_id) 
print user_info 

当我搜索 user_id 时,我从 API 控制台得到了什么

{ 
    "meta":  { 
         "code": 200 
    }, 
    "data":  { 
    "username": "IGname", 
    "bio": "Comments, 
    "website": "http://instagram, 
    "profile_picture":             "picture", 
    "full_name": "IGRealname", 
    "counts":  { 
        "media": Number1, 
        "followed_by": Number2, 
        "follows": Number3 
    }, 
    "id": "IGUserID" 
} 

我希望获取用户名、后续内容,然后是要输出到 python 的字段。

我得到的只是用户名,仅此而已。

请您参考如下方法:

你可以使用这个:

user_followers, next_ = api.user_followed_by()  
            while next_: 
                    more_user_followers, next_ = api.user_followed_by(with_next_url=next_) #this will get you all your followers 
                    user_followers.extend(more_user_followers) 
 
len(user_followers) #this is the numbers of followers you have