.. automethod:: API.get_user
-User methods
-------------
-
-.. method:: API.me()
-
- Returns the authenticated user's information.
-
- :rtype: :class:`User` object
-
-
Direct Message Methods
----------------------
def testsearchusers(self):
self.api.search_users('twitter')
- @tape.use_cassette('testme.json')
- def testme(self):
- me = self.api.me()
- self.assertEqual(me.screen_name, username)
-
@tape.use_cassette('testlistdirectmessages.json')
def testlistdirectmessages(self):
self.api.list_direct_messages()
@tape.use_cassette('testsendanddestroydirectmessage.json')
def testsendanddestroydirectmessage(self):
- me = self.api.me()
+ me = self.api.verify_credentials()
# send
sent_dm = self.api.send_direct_message(me.id, text='test message')
@tape.use_cassette('testupdateprofilecolors.json')
def testupdateprofilecolors(self):
- original = self.api.me()
+ original = self.api.verify_credentials()
updated = self.api.update_profile(profile_link_color='D0F900')
# restore colors
@tape.use_cassette('testupdateprofile.json')
def testupdateprofile(self):
- original = self.api.me()
+ original = self.api.verify_credentials()
profile = {
'name': 'Tweepy test 123',
'location': 'pytopia',
), command='STATUS', media_id=media_id, upload_api=True, **kwargs
)
- def me(self):
- """ Get the authenticated user """
- return self.get_user(screen_name=self.auth.get_username())
-
@payload('direct_message')
def get_direct_message(self, id, **kwargs):
""" :reference: https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/get-event
"""Apply authentication headers to request"""
raise NotImplementedError
- def get_username(self):
- """Return the username of the authenticated user"""
- raise NotImplementedError
-
class OAuthHandler(AuthHandler):
"""OAuth authentication handler"""
except Exception as e:
raise TweepyException(e)
- def get_username(self):
- if self.username is None:
- api = API(self)
- user = api.verify_credentials()
- if user:
- self.username = user.screen_name
- else:
- raise TweepyException('Unable to get username,'
- ' invalid oauth token!')
- return self.username
-
class OAuth2Bearer(AuthBase):
def __init__(self, bearer_token):