[英]Can't retweet with tweepy - Python
i'm trying to create a bot to retweet #dogs. 我正在尝试创建一个机器人来转发#dogs。 This is my code
这是我的代码
import tweepy
consumer_key = 'XXXXXXXXX'
consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXX'
access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token_secret = 'XXXXXXXXXXXXXXXXXXXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
user = api.me()
print(user.name)
def main():
search = ('#dogs')
for tweet in tweepy.Cursor(api.search, search).items(1):
try:
tweet.retweet()
print('Tweet Retweeted')
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break
main()
When i run it, i get my username from (user.name) but it never sends the retweet. 当我运行它时,我从(user.name)获取我的用户名,但它从未发送过转发。
CMD output: CMD输出:
C:\Users\xd\Desktop>python rt_bot.py
Dom
api.retweet(tweet)
instead of tweet.retweet()
should probably do it. api.retweet(tweet)
而不是tweet.retweet()
应该可以做到。
For more reference: http://docs.tweepy.org/en/v3.5.0/api.html?highlight=retweet 有关更多参考: http : //docs.tweepy.org/en/v3.5.0/api.html?highlight=retweet
EDIT: From my comment - keep tweet.retweet()
but remove the 1 from tweepy.Cursor(api.search, search).items()
, so that you search through all tweets rather than just the first tweet you can. 编辑:从我的评论-保留
tweet.retweet()
但从tweepy.Cursor(api.search, search).items()
删除1,以便您搜索所有推文,而不仅仅是搜索第一条推文。
The parameter of items()
determines how many tweets you search through, and leaving it blank will allow you to search through as many as tweepy allows items()
的参数确定您搜索的推文数量,将其保留为空白将使您可以搜索tweepy所允许的数量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.