req = Request(token_url) req.add_header("Authorization", auth_value) req.add_header("Content-Type", "application/x-www-form-urlencoded") try: # HTTP POST res = urlopen(req, body) except URLError as e: print(e) content = e.read().decode("utf-8") e.close() return content else: content = res.read().decode("utf-8") res.close() return content jsonfile = JsonFile("mb-auth.json") auth = jsonfile.read() client_id = auth["client_id"] client_secret = auth["client_secret"] token_url = "https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/token" refresh_token = auth["refresh_token"] auth_value = get_auth_value(client_id, client_secret) print(auth_value) access_token_json = get_refreshed_access_token_json( token_url, refresh_token, auth_value) print(access_token_json)
try: # HTTP POST res = urlopen(req, body) except URLError as e: print(e) content = e.read().decode("utf-8") e.close() return content else: content = res.read().decode("utf-8") res.close() return content token_url = "https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/token" jsonfile = JsonFile("mb-auth.json") auth = jsonfile.read() auth_value = get_auth_value(auth["client_id"], auth["client_secret"]) print("Auht val:",auth_value) access_token_json = get_access_token_json( token_url, auth["code"], auth_value, auth["callback_url"]) print("Acess token:", access_token_json) data = json.loads(access_token_json) auth["access_token"] = data["access_token"] auth["refresh_token"] = data["refresh_token"] jsonfile.write(auth)
# HTTP POST res = urlopen(req, body) except URLError as e: print(e) content = e.read().decode("utf-8") e.close() return content else: content = res.read().decode("utf-8") res.close() return content token_url = "https://api.fitbit.com/oauth2/token" jsonfile = JsonFile("fitbit-auth.json") auth = jsonfile.read() auth_value = get_auth_value(auth["client_id"], auth["client_secret"]) print(auth_value) access_token_json = get_access_token_json(token_url, auth["code"], auth_value, auth["callback_url"]) print(access_token_json) data = json.loads(access_token_json) auth["access_token"] = data["access_token"] auth["refresh_token"] = data["refresh_token"] auth["user_id"] = data["user_id"] jsonfile.write(auth)
req = Request(url) req.add_header("Authorization", auth_value) try: res = urlopen(req) except URLError as e: print(e) content = e.read().decode("utf-8") e.close() return content else: content = res.read().decode("utf-8") res.close() return content token_type = "Bearer" jsonfile = JsonFile("fitbit-auth.json") auth = jsonfile.read() # yyyy-mm-dd date = DateTime.yyyymmdd(DateTime.yesterday()) # date = "2016-07-30" # yyyy-MM-dd auth_value = "{} {}".format(token_type, auth["access_token"]) print(auth_value) activity_json = get_activity(auth["user_id"], date, auth_value) pprint.pprint(json.loads(activity_json))
import urllib.parse from mycommon import JsonFile def get_fitbit_auth_url(auth_url, scope, client_id, redirect_uri): # Using OAuth 2.0 — Fitbit Web API Docs # Authorization Code Grant Flow: Authorization Page # https://dev.fitbit.com/docs/oauth2/#authorization-page params = { "client_id": client_id, "response_type": "code", "scope": scope, "redirect_uri": redirect_uri, } qs = urllib.parse.urlencode(params) return auth_url + "?" + qs auth_url = "https://www.fitbit.com/oauth2/authorize" scope = "activity heartrate location nutrition profile settings sleep social weight" auth = JsonFile("fitbit-auth.json").read() fitbit_auth_url = get_fitbit_auth_url(auth_url, scope, auth["client_id"], auth["callback_url"]) print("{}".format(fitbit_auth_url))
import urllib.parse from mycommon import JsonFile def get_fitbit_auth_url(auth_url, scope, client_id, redirect_uri): # Using OAuth 2.0 — MB Web API Docs # Authorization Code Grant Flow: Authorization Page # https://developer.mercedes-benz.com/content-page/oauth-documentation params = { "client_id": client_id, "response_type": "code", "scope": scope, "redirect_uri": redirect_uri, } qs = urllib.parse.urlencode(params) return auth_url + "?" + qs auth_url = "https://api.secure.mercedes-benz.com/oidc10/auth/oauth/v2/authorize" scope = "mb:vehicle:status:general mb:user:pool:reader mb:vehicle:mbdata:evstatus" auth = JsonFile("mb-auth.json").read() mb_auth_url = get_fitbit_auth_url(auth_url, scope, auth["client_id"], auth["callback_url"]) print("{}".format(mb_auth_url))