Skip to content

Instantly share code, notes, and snippets.

@Rub21
Created March 6, 2024 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rub21/7bb178f8580401a20f04966e9adcae39 to your computer and use it in GitHub Desktop.
Save Rub21/7bb178f8580401a20f04966e9adcae39 to your computer and use it in GitHub Desktop.
from requests_oauthlib import OAuth2Session
client_id = r'CV5dBzhOwDZkZeCj4xyosVOIJAkTuCZm-HlCK0P2Sfw'
client_secret = r'l3kMZgDojx8Kylh1_L0Eh9WD7KFORM4UEKZku66A7GY'
redirect_uri = 'http://127.0.0.1:8111/oauth_authorization'
scope = ["read_prefs"]
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
authorization_url, state = oauth.authorization_url('https://www.openstreetmap.org/oauth2/authorize')
print(f"Visit {authorization_url} and paste the code in")
code = input()
token = oauth.fetch_token('https://www.openstreetmap.org/oauth2/token',
code=code,
client_secret=client_secret
)
print(token)
# save the token in a file somewhere or something
prefs = oauth.request(method='GET',url='https://www.openstreetmap.org/api/0.6/user/preferences')
print(prefs.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment