使用tweepy streaming示例我發現here您可以編輯過濾器來搜索「@yourhandle」。
您可以訪問誰啾啾通過添加人:
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print status.text
print status.user.screen_name #<----------------THIS LINE
會告訴你誰啾啾你。你可以下一個嘗試使用更新狀態:
api.update_status("my update", in_reply_to_status_id = tweetid)
的鳴叫ID可以使用得到:
status.id
代碼應該是這樣的:
import tweepy
consumer_key = "xxx"
consumer_secret = "xxx"
access_key = "xxx"
access_secret = "xxx"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print status.text
print status.user.screen_name
api.update_status("Insert Auto Reply Text Here", in_reply_to_status_id = status.id)
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['@rishi'])
您將需要創建一個dev Twitter帳戶爲此工作並輸入您自己的安全令牌。我目前無法測試寫入時間表,因爲我的只讀。