推特的追随者(tweepy)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了推特的追随者(tweepy)相关的知识,希望对你有一定的参考价值。

我正在尝试下载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)
答案

如果我理解正确,那么你想要获得每个粉丝的所有粉丝的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

以上是关于推特的追随者(tweepy)的主要内容,如果未能解决你的问题,请参考以下文章

推特的发现页面在哪里

我没有收到来自推特的推文

带有护照推特的sails.js

Python推特开发库tweepy基本操作:Twitter for Python

tweepy 文档 [关闭]

有钱任性,马斯克变推特最大股东!然而,特斯拉发布重大消息…