推特的追随者(tweepy)

问题描述 投票:0回答:1

我正在尝试下载twitter的关注者和关注者的关注者。 T代码似乎有效,但它没有下载我的所有粉丝。它下载了一部分,在这部分我认为它运作良好。但为什么不呢?

为什么?

-- coding: utf-8 --

"""
@author: Mik
"""
import csv 
import time 

import tweepy

# Copy the api key, the api secret, the access token and the access token secret from the relevant page on your Twitter app 

api_key = ''
api_secret = ''
access_token = '-'
access_token_secret = ''

# You don't need to make any changes below here # This bit authorises you to ask for information from Twitter 
auth = tweepy.OAuthHandler(api_key, api_secret) 
auth.set_access_token(access_token, access_token_secret) 
# The api object gives you access to all of the http calls that Twitter accepts 
api = tweepy.API(auth) 

#User we want to use as initial node 
user=''


#This creates a csv file and defines that each new entry will be in a new line 
csvfile=open(user+'network2.csv', 'w') 
spamwriter = csv.writer(csvfile, delimiter=' ',quotechar='|', quoting=csv.QUOTE_MINIMAL) 

#This is the function that takes a node (user) and looks for all its followers #and print them into a CSV file... and look for the followers of each follower... 
def fib(n,user,spamwriter):
    if n>0:
        #There is a limit to the traffic you can have with the API, so you need to wait 
        #a few seconds per call or after a few calls it will restrict your traffic 
        #for 15 minutes. This parameter can be tweeked 
        time.sleep(40) 

        #This is for private users that we wont be able to see their followers
        try:
            users=tweepy.Cursor(api.followers, screen_name = user, wait_on_rate_limit = True).items()
            for follower in users:
                spamwriter.writerow([user+';'+follower.screen_name]) 
                fib(n-1,follower.screen_name,spamwriter) 
                #n defines the level of autorecurrence

        except tweepy.TweepError:
                print("Failed to run the command on that user, Skipping...")



n=2
fib(n,user,spamwriter)
python twitter tweepy
1个回答
1
投票

如果我理解正确,那么你想要获得每个粉丝的所有粉丝的ID。使用如下的逻辑,它将为您提供每15分钟3000名粉丝的详细信息

import tweepy
#twitter credentials here---------------------------------------------------
auth = tweepy.OAuthHandler(your keys)
auth.set_access_token(your keys)
api = tweepy.API(auth)

iter1 = tweepy.Cursor(api.followers, screen_name = 'your_screen_name',count = 200).pages()

for request in range(15):
      your_200_followers = next(iter1)
      for each_follower in your_200_followers:
               variable = each_follower.followers_ids
               #store the <list> variable somewhere
© www.soinside.com 2019 - 2024. All rights reserved.