8000 Add function to get user_id of authenticating user by parantapa · Pull Request #757 · tweepy/tweepy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add function to get user_id of authenticating user #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tweepy/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, consumer_key, consumer_secret, callback=None):
self.access_token_secret = None
self.callback = callback
self.username = None
self.user_id = None
self.oauth = OAuth1Session(consumer_key,
client_secret=consumer_secret,
callback_uri=self.callback)
Expand Down Expand Up @@ -102,6 +103,8 @@ def get_access_token(self, verifier=None):
resp = self.oauth.fetch_access_token(url)
self.access_token = resp['oauth_token']
self.access_token_secret = resp['oauth_token_secret']
self.username = resp["screen_name"]
self.user_id = resp["user_id"]
return self.access_token, self.access_token_secret
except Exception as e:
raise TweepError(e)
Expand Down Expand Up @@ -134,11 +137,23 @@ def get_username(self):
user = api.verify_credentials()
if user:
self.username = user.screen_name
self.user_id = user.id
else:
raise TweepError('Unable to get username,'
' invalid oauth token!')
return self.username

def get_user_id(self):
if self.user_id is None:
api = API(self)
user = api.verify_credentials()
if user:
self.username = user.screen_name
self.user_id = user.id
else:
raise TweepError('Unable to get user_id,'
' invalid oauth token!')
return self.user_id

class OAuth2Bearer(AuthBase):
def __init__(self, bearer_token):
Expand Down
0