Created
October 27, 2014 16:31
-
-
Save philngo/d061ad5f94b9c6f911e2 to your computer and use it in GitHub Desktop.
Smartthings python workflow
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
from requests_oauthlib import OAuth2Session | |
import argparse | |
import json | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("client_id") | |
parser.add_argument("client_secret") | |
args = parser.parse_args() | |
base_url = "https://graph.api.smartthings.com" | |
redirect_uri = "/oauth/callback" | |
authorize_uri = base_url + "/oauth/authorize" | |
token_uri = base_url + "/oauth/token" | |
endpoint_uri = base_url + "/api/smartapps/endpoints" | |
scope = ["app"] | |
client_id = args.client_id | |
client_secret = args.client_secret | |
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope) | |
authorization_url, state = oauth.authorization_url(authorize_uri) | |
print 'Please go to %s and authorize access.' % authorization_url | |
authorization_response = raw_input('Enter the full callback URL: ') | |
token = oauth.fetch_token( | |
token_uri, | |
authorization_response=authorization_response, | |
client_secret=client_secret) | |
r = oauth.get(endpoint_uri) | |
print r.content | |
endpoint = [response["url"] for response in json.loads(r.content)][0] | |
print base_url + endpoint | |
print oauth.get(base_url + endpoint + "/switch").content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment