Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-Tweepy-我需要添加什么才能使此代码回复到帐户而不是关键字?_Python_Twitter_Tweepy_Twitterapi Python - Fatal编程技术网

Python-Tweepy-我需要添加什么才能使此代码回复到帐户而不是关键字?

Python-Tweepy-我需要添加什么才能使此代码回复到帐户而不是关键字?,python,twitter,tweepy,twitterapi-python,Python,Twitter,Tweepy,Twitterapi Python,这是我当前使用的代码,它会立即响应任何包含任何关键字的tweet。相反,我希望更改此代码以自动响应特定帐户(每当它发出tweet时)。要做到这一点,我需要添加或删除什么?这段当前代码有效,我只是想知道如何更改它回复的内容 import tweepy from tweepy import Stream from tweepy.streaming import StreamListener import json class StdOutListener(StreamListener):

这是我当前使用的代码,它会立即响应任何包含任何关键字的tweet。相反,我希望更改此代码以自动响应特定帐户(每当它发出tweet时)。要做到这一点,我需要添加或删除什么?这段当前代码有效,我只是想知道如何更改它回复的内容

import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener

import json

class StdOutListener(StreamListener):
    def on_data(self, data):
        clean_data = json.loads(data)
        tweetId = clean_data["id"]
        tweet = "YOUR REPLY HERE"
        respondToTweet(tweet, tweetId)

def setUpAuth():
    auth = tweepy.OAuthHandler("consumer_key", "consumer_secret")
    auth.set_access_token("access_token", "access_token_secret")
    api = tweepy.API(auth)
    return api, auth

def followStream():
    api, auth = setUpAuth()
    listener = StdOutListener()
    stream = Stream(auth, listener)
    stream.filter(track=["KEYWORDS"])

def respondToTweet(tweet, tweetId):
    api, auth = setUpAuth()
    api.update_status(tweet, in_reply_to_status_id=tweetId, auto_populate_reply_metadata=True)

if __name__ == "__main__":
    followStream()
解决了

对于任何想知道这是如何做到的人,以下是我所做的:

我在代码中更改了这一行:

stream.filter(track=["KEYWORDS"])
致:

TWITTER_ID=您想要自动回复的用户的TWITTER ID,可以通过将其句柄插入tweeterid.com找到

例如,realdonaldtrump的twitter id是25073877,因此您可以将twitter_id替换为25073877

stream.filter(follow=["TWITTER_ID"])