如何解决是否可以使用Tweepy模块获取添加关注者的日期?
如果我不知道如何搜索Tweepy文档,我向您致歉。一般来说,我对python /编程还是很陌生。
我写了一个小脚本来提取我管理的工作帐户的Twitter关注者数据。我想调查何时关注者添加我们的情况,以查看我们的帖子是否在增加参与度。我不知道是否可以使用Tweepy模块提取此特定信息(当关注者添加我们时)?
在此先感谢您的帮助。我的MWE:
import tweepy
import pandas as pd
# Load API keys
consumer_key = "my_consumer_key"
consumer_secret = "my_consumer_secret"
access_token = "my_access_token"
access_token_secret = "my_access_token_secret"
# Authenticate access to Twitter API
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
# Get the list of followers for the account
followers = api.followers_ids()
# Create a user map
userMap = {}
# Loop over all users
for f in followers:
# create a temporary list
tempList = []
try:
tweets = api.user_timeline(f,count = 33) # pull the 33 most recent tweets
except tweepy.TweepError:
print('Failed to run command.') # Tweepy throws an error if a user hasn't tweeted
# Loop over all tweets per each user f
for t in tweets:
tempList.append(t)
userMap[f] = tempList
# Create lists of pertinent data
dateList = []
favList = []
rtList = []
keyList = []
def genList(tweetList):
for tweets in tweetList:
for t in tweets:
keyList.append(str(t.id))
dateList.append(str(t.created_at))
favList.append(str(t.favorite_count))
rtList.append(str(t.retweet_count))
genList(userMap.values())
# Create a pandas data frame
df = pd.DataFrame(list(zip(keyList,dateList,favList,rtList)),columns = ['userID','created_at','favorited','retweeted'])
解决方法
Twitter不提供此信息。
followers/list
(在Tweepy followers()
方法中)返回User对象的列表。看起来唯一的解决方案是监视更改并自己管理历史记录。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。