试图在Instagram API中找到关注者数量

时间:2014-10-10 19:07:07

标签: python json instagram

我希望找到特定用户的关注者数量,就像您使用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。

我得到的只是用户名,就是这样。

2 个答案:

答案 0 :(得分:1)

您可以使用:

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

答案 1 :(得分:0)

当您致电用户信息时,它将返回给您。端点是: https://api.instagram.com/v1/users/USERID/

您想要的数据位于"计数"阵列。

但是,在您的示例中,用户可能是私有的。当它是私人的时候,你无法获得下级媒体的统计数据。响应将有400个标题(BAD REQUEST),正文将是:

{"meta":
   {"error_type":"APINotAllowedError",
    "code":400,"error_message":"you cannot view this resource"
   }
 }

如果您愿意,请在此处注释我们仔细检查的用户ID。

相关问题