[英]Using tweepy to follow people tweeting a specific hashtag
This is one of my first python projects and I'm using Tweepy to trying to search for a specific hashtag and follow those people tweeting that hashtag. 这是我的第一个python项目之一,我正在使用Tweepy尝试搜索特定的主题标签,并关注那些发布该主题标签的人。 I don't understand why this doesn't work and I've tried to append followers to list but nothing either. 我不明白为什么这行不通,并且我尝试将追随者添加到列表中,但什么也没有。 I've read the tweepy docs and this is what I've come up with: 我读过tweepy文档,这是我想出的:
import tweepy
import time
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
for follower in tweepy.Cursor(api.search, q="#kenbone").items():
api.create_friendship(screen_name = follower)
print(follower)
Want you are getting in your loop, the variable follower
, is a user
object with a huge lot of information about the user, and not just a name as you seem to believe. 希望您进入循环,变量follower
是一个user
对象,它具有有关该用户的大量信息,而不仅仅是您似乎相信的名称。 To get the screen name of a user
object, use follower.screen_name
: 要获取user
对象的屏幕名称,请使用follower.screen_name
:
api.create_friendship(screen_name = follower.screen_name)
screen_name是author属性的一部分,这对我有用
api.create_friendship(screen_name = follower.author.screen_name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.