简体   繁体   中英

Accessing the username of all the followers of a user in Instagram using Scrapy or Instagram Python API

How can I get the username of each of the followers of a user in instagram? In the json I can only have access to the number of the followers. Here is the URL for json processing I am using:

"https://www.instagram.com/buzzfeed/?__a=1"
pprint(json_response["user"]["followed_by"]["count"])

Here's the beginning of pprint(json_response["user"])

    {u'biography': u"Hi, we're:q
 BuzzFeed dot com the website. Download our app:",
     u'blocked_by_viewer': False,
     u'connected_fb_page': None,
     u'country_block': False,
     u'external_url': u'http://bzfd.it/2cpjV5B',
     u'external_url_linkshimmed': u'http://l.instagram.com/?e=ATN_0_BAWjtGnChrZAtmnHUKqbPDjr3JcppPl3dQc7xbokFd56UvRHua36v9XsY&u=http%3A%2F%2Fbzfd.it%2F2cpjV5B',
     u'followed_by': {u'count': 2527289},
     u'followed_by_viewer': False,
     u'follows': {u'count': 127},
     u'follows_viewer': False,
     u'full_name': u'BuzzFeed',
     u'has_blocked_viewer': False,
     u'has_requested_viewer': False,
     u'id': u'1538653985',
     u'is_private': False,
     u'is_verified': True,
     u'media': {u'count': 2175,
                u'nodes': [{u'__typename': u'GraphVideo',
                            u'caption': u'me when I finally get paid',
                            u'code': u'BRJs_2Zj143',
                            u'comments': {u'count': 1330},
                            u'comments_disabled': False,
                            u'date': 1488491778,
                            u'dimensions': {u'height': 640, u'width': 640},

I can see that u'follows_viewer': False but this is public account and I can see the followers of buzzfeed from its instagram account. Any idea is highly suggested.

UPDATE: I tried this other method by using Instagram API and I get None, not sure what went wrong:

print(api.user_followed_by(user_id=53112486))
([], None)
print(api.user_follows(user_id=53112486))
([], None)

I followed this method for getting my access token, is that wrong?

https://api.instagram.com/oauth/authorize/?client_id=YOUR-CLIENT-ID&redirect_uri=YOUR-REDIRECT-URI&response_type=code&scope=basic+comments+follower_list+likes+relationships+public_content

I used http://localhost:8515/oauth_callback for my redirect_uri

And it asked me this: 在此处输入图片说明

Which I authorized!

That said, I can get the counts of my own account (53112486 is my user_id):

info = api.user(user_id=53112486)
print(info.counts)

Also, when I tried

https://api.instagram.com/v1/users/self/followed-by?access_token=MINE

I got the following!

{"pagination": {}, "meta": {"code": 200}, "data": []}

These both return ([], None) :

 50         for page in api.user_followed_by( as_generator=True):
 51             print(str(page))
 52 
 53         print(api.user_follows(user_id=53112486))

You cannot get other user's followers using Instagram APIs anymore, you can only get followers/following list for the user that is authenticated. You will need to get your app reviewed and approved by instagram and go to LIVE mode to get access to all data from API and also you need "followers_list" scope permission.

The code in first part of the question is using private Instagram API and that does not support getting followers list.

(in short you have just mixed up code from all over the place, it is not even related, one is public api and other private api, you need to read docs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM