Skip to content

Instantly share code, notes, and snippets.

@blairg23
Last active January 21, 2022 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blairg23/dc421453b035321a5e27 to your computer and use it in GitHub Desktop.
Save blairg23/dc421453b035321a5e27 to your computer and use it in GitHub Desktop.
Oauth Example Authentication with Flickr using requests_oauthlib in Python
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.
@tomquirk
Copy link

tomquirk commented Sep 24, 2017

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