Last active
January 21, 2022 14:01
-
-
Save blairg23/dc421453b035321a5e27 to your computer and use it in GitHub Desktop.
Oauth Example Authentication with Flickr using requests_oauthlib in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests_oauthlib | |
api_key = <api_key_here> | |
api_secret = <api_secret_here> | |
# OAuth URLs | |
request_token_url = 'https://www.flickr.com/services/oauth/request_token' | |
access_token_url = 'https://www.flickr.com/services/oauth/access_token' | |
authorization_url = 'https://www.flickr.com/services/oauth/authorize' | |
callback_uri = <callback_uri_here> | |
oauth_session = requests_oauthlib.OAuth1Session(client_key=api_key, client_secret=api_secret, signature_method=u'HMAC-SHA1', signature_type=u'AUTH_HEADER', callback_uri=callback_uri) | |
# First step, fetch the request token: | |
request_token = oauth_session.fetch_request_token(request_token_url) | |
# Second step, follow this link and authorize: | |
print oauth_session.authorization_url(authorization_url) | |
# Third step, fetch the access token: | |
redirect_response = raw_input('Paste the full redirect URL here.') | |
print oauth_session.parse_authorization_response(redirect_response) | |
print oauth_session.fetch_access_token(access_token_url) | |
# Done! You can now make authenticated requests using the token and token secret. |
Hey all,
If you have the urge, check out the Python Flickr API. Consult the wiki for steps similar to the ones on this gist for getting tokens and authenticating!
@blairg23 - would love to get your code in the project. Your method is the best I've found. Consider a PR!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice work! You've made this process as simple as I think it can possibly be.
Python 3+ needs a few tweaks to get it working:
print
statements require parenthesis around the entire valueraw_input
has been renamed toinput