Last active
December 28, 2015 10:19
-
-
Save khibma/7485243 to your computer and use it in GitHub Desktop.
Make arcgis.com token
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
def gentoken(username, password, referer, expiration=60): | |
#Re-usable function to get a token required for Admin changes | |
referer = "http://www.arcgis.com/" | |
query_dict = {'username': username, | |
'password': password, | |
'expiration': str(expiration), | |
'client': 'referer', | |
'referer': referer, | |
'f': 'json'} | |
query_string = urllib.urlencode(query_dict) | |
tokenUrl = "https://www.arcgis.com/sharing/rest/generateToken" | |
tokenResponse = urllib.urlopen(tokenUrl, urllib.urlencode(query_dict)) | |
token = json.loads(tokenResponse.read()) | |
if "token" not in token: | |
print token['messages'] | |
import sys | |
sys.exit() | |
else: | |
# Return the token to the function which called for it | |
return token['token'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment