Created
March 16, 2017 16:30
-
-
Save anonymous/a3d4b578f4ac49acb26f59ec2ea8b273 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ """ Interacting with the Narro.co API with Python ### Implementation 1. ask narro for authorization_code 2. visit the url to grant permission 3. paste the authorization_code into the script 4. exchange the authorization_code + secret_key for an access token 5. use the access token """ import requests CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" CLIENT_SECRET = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" CLIENT_URI = "http://mysite.com/narro/callback.php" REDIRECT_URI = 'http://mysite.com/narro/redirect.php' AUTHORIZE_URL = "https://www.narro.co/oauth2/authorize/" ACCESS_TOKEN_URL = "https://narro.co/oauth2/token/" # 1. ask narro for authorization_code r = requests.post('{}?grant_type=authorization_code&client_id={}&redirect_uri={}&response_type=code' .format(AUTHORIZE_URL, CLIENT_ID, REDIRECT_URI)) # 2. visit the url to grant permission print(r.url) print("\n") # 3. paste the authorization_code into the script SESSION_CODE = input("do you have the pin?") # 4. exchange the authorization_code + secret_key for an access token q = requests.post( ACCESS_TOKEN_URL, data={ 'grant_type': 'authorization_code', 'code': SESSION_CODE, 'client_id': CLIENT_ID, 'client_secret': CLIENT_SECRET, 'redirect_uri': REDIRECT_URI } ) print("\n") print(q) # As I understand it, this should return a JSON response that I could see with q.json(). Nope, 404.