本文整理汇总了Python中tweepy.OAuthHandler.get_username方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthHandler.get_username方法的具体用法?Python OAuthHandler.get_username怎么用?Python OAuthHandler.get_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tweepy.OAuthHandler
的用法示例。
在下文中一共展示了OAuthHandler.get_username方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TwitterPlayer
# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import get_username [as 别名]
class TwitterPlayer(player.Player):
def __init__(self, model, code, access_token, access_token_secret, opponent):
player.Player.__init__(self, model, code)
self._opponent = opponent
self._last_id = None
self._auth = OAuthHandler(auth.consumer_key, auth.consumer_secret)
self._auth.set_access_token(access_token, access_token_secret)
self._api = API(self._auth)
self._listener = TwitterListener(self, self._api)
self._stream = Stream(self._auth, self._listener)
@property
def username(self):
return self._auth.get_username()
def allow(self):
print 'This is the opponent\'s turn...'
self._stream.userstream()
def update(self, event):
if event.player == self.code:
return
message = '@%s %s' % (self._opponent, self._model.events[-1][1])
self.tweet(message)
def tweet(self, message):
if self._last_id is None:
self._api.update_status(message)
else:
self._api.update_status(message, self._last_id)
示例2: StdOutListener
# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import get_username [as 别名]
consumer_key=Config.get(twcred,"consumer_key")
consumer_secret=Config.get(twcred,"consumer_secret")
access_token=Config.get(twcred,"access_token")
access_token_secret=Config.get(twcred,"access_token_secret")
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
pprint (vars(auth))
auth.set_access_token(access_token, access_token_secret)
pprint (vars(auth))
print auth.get_username()
stream = Stream(auth, l)
stream.filter(track=['basketball'])
示例3: OpenSesame
# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import get_username [as 别名]
"keywords: " + keywords + " \n" +
"welcome_msg: " + welcome_msg + " \n" +
"tease_on: " + tease_on_regex + " \n" +
"teaser_text: " + teaser_text + " \n" +
"ffwd_msg: " + ffwd_msg + " \n" +
"log_dir: " + log_dir + "\n" +
"log_level: " + log_level
)
if os.uname()[4].startswith("arm"):
logging.info("Running on a Raspberry Pi.")
is_rpi = True
import RPi.GPIO as GPIO
else:
logging.info("Not a Raspberry Pi. Any of the GPIO commands will not be executed.")
if is_rpi:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(relay_pin, GPIO.OUT, initial = GPIO.LOW)
l = OpenSesame()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
username = auth.get_username()
api = tweepy.API(auth)
stream = Stream(auth, l)
stream.userstream()