-
-
Save stuboo/ada21fbfd4f7e35f70b3aec320ea9bcc to your computer and use it in GitHub Desktop.
Interacting with the Narro.co API with Python
This file contains 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
""" | |
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://www.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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment