Created
December 9, 2021 05:52
-
-
Save stephenquan/f8af3f15a4514d723d536a34c1a552c9 to your computer and use it in GitHub Desktop.
oauth2refresh.py
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 json, urllib.parse, urllib.request | |
CLIENT_ID = 'appstudioweb' | |
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob' | |
# Prompt for refresh token | |
refresh_token = input('Copy and paste refresh_token here: ') | |
# Obtain token | |
target = "https://www.arcgis.com/sharing/rest/oauth2/token" | |
parameters = { } | |
parameters['grant_type'] = 'refresh_token' | |
parameters['client_id'] = CLIENT_ID | |
parameters['refresh_token'] = refresh_token | |
parameters['f'] = 'json' | |
data = urllib.parse.urlencode(parameters).encode('ascii') | |
response = { } | |
with urllib.request.urlopen(target, data) as f: | |
response = json.load(f) | |
print('') | |
print(response) | |
if 'error' in response: | |
print(response.get('error')) | |
raise Exception(response.get('error').get('message')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment