2014-06-05 2 views
0

나는 관련된 트위터 핸들로 보내진 트윗에 응답 할 트위터 봇을 만들고 있습니다. 해시 태그로 스트림을 필터링하는 방법에 대한 설명서를 보았지만 멘션별로 필터링하는 방법을 알지 못합니다. 로봇과 관련된 트위터 핸들이 twitter_bot 인 경우 예를 들어, 내가 같은 것을 할 싶습니다 :언급하여 스트림을 필터링하는 방법

listener = CustomListener() 
stream = tweepy.Stream(OAuth, listener) 

# Is there a parameter here that accomplishes this?? 
stream.filter(mentions=["twitter_bot"]) 

난 단지 누군가가 twitter_bot 핸들에서 짹짹 사건을 처리하고 싶습니다.

즉. "@twitter_bot 어때?"

감사합니다.

+1

여기에, 난 아무것도 찾을 수 없습니다,하지만 당신은 수도 소스 코드는 https://github.com/tweepy/tweepy/blob/master/tweepy/streaming.py입니다. –

답변

1

멘션에 REST API endpoint이 있으며 tweepy와 함께 사용할 수 있습니다. documentation은 구식이며, 메소드 이름이 mentions_timeline로 변경되었습니다. 코드를 다음과 키를 변경/비밀로 https://github.com/tweepy/tweepy/blob/master/tweepy/api.py#L79

당신이 당신의 인증 된 사용자의 언급 얻을 것이다 : 여기 tweepy의 방법이

import tweepy 

auth = tweepy.OAuthHandler(consumer_key='AAA', consumer_secret='BBB') 
auth.set_access_token('CCC', 'DDD') 
api = tweepy.API(auth_handler=auth, secure=True, retry_count=5) 

mentions = api.mentions_timeline() 
for mention in mentions: 
    print mention.id, mention.author.screen_name, mention.text 
관련 문제