2014-10-10 55 views
2

我期待找到跟隨數爲特定的用戶就像你如果你使用Instagram的API控制檯:試圖找到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 

什麼我從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" 
} 

我希望得到的用戶名user_ID的控制檯,如下,其次是場輸出到蟒蛇。

我所得到的只是用戶名,就是這樣。

回答

0

當你要求用戶信息時,它會返回給你。端點是: 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,我們仔細檢查它。

+0

這是計數陣列英寸在API控制檯中,我可以獲取所有我想要的信息,但是我不知道如何通過Python訪問相同的信息。這就是我要找的東西。對不起,如果我最初不清楚。 – Caveman1515 2014-10-13 12:49:31

+0

好吧..我沒有在python練習..我無法幫到你。抱歉。 – 2014-10-14 03:16:28

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