【问题标题】:Trying to find follower count in Instagram API尝试在 Instagram API 中查找关注者数量
【发布时间】:2014-10-10 19:07:07
【问题描述】:

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

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

【问题讨论】:

    标签: python json instagram


    【解决方案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
    

    【讨论】:

      【解决方案2】:

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

      您想要的数据在“counts”数组中。

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

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

      如果您愿意,请在此处评论用户 ID,以便我们仔细检查。

      【讨论】:

      • 它在计数数组中。在 API 控制台中,我可以获得我想要的所有信息,但是我不知道如何通过 Python 访问相同的信息。这就是我正在寻找的东西。对不起,如果我一开始不清楚。
      • 好的..我没有在python中练习过..我帮不了你。对不起。
      猜你喜欢
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 2019-03-07
      • 2019-07-11
      • 1970-01-01
      相关资源
      最近更新 更多