我正在尝试使用Tweepy创建一个程序,当任何随机用户用短语“ Cats are cool”提及时,它的响应为“ Cats are cool”。我遇到的问题是,假设您需要输入提及您的人的ID?我希望机器人能够自动回复,而无需输入ID。如果这没有意义,我可以澄清更多。
import tweepy
import time
consumer_key='XXXXXXXXXXXXXXXXXXXX'
consumer_secret='XXXXXXXXXXXXXXXXXXXXXXXXX''
access_token_key='XXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token_secret='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth = tweepy.OAuthHandler('XXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
auth.set_access_token('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
api = tweepy.API(auth)
user = api.me()
def creds_validated():
verify_creds = api.verify_credentials()
if verify_creds:
print('Successfully authenticated... script started.')
print(user.name)
else:
print('Invalid credentials.')
creds_validated()
api.update_status('Cats are indeed cool')