Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.8 kB
5
Indexable
Never
            ## ACCESS TOKEN REQUEST ##
            ## ACCESS TOKEN REQUEST ##
            headers = {
                "Host": "api.fitbit.com",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0",
                "Accept": "application/json, text/javascript, */*; q=0.01",
                "Accept-Language": "en",
                "Accept-Encoding": "gzip, deflate, br",
                "Referer": 'https://accounts.fitbit.com/',
                "Content-Type": "application/x-www-form-urlencoded",
                "Origin": "https://accounts.fitbit.com",
                "Connection": "keep-alive",
                "TE": "trailers"
            }
            data = 'grant_type=password&username='+userName+'&password='+fPassword+'&session-data={\"browser-name\":\"Firefox\",\"browser-version\":\"99.0\",\"os-name\":\"Windows\",\"os-version\":\"10\",\"device-model\":\"\",\"device-manufacturer\":\"\",\"device-name\":\"Windows\"}&client_id=228TQF&access_token=on&enableRefreshToken=true'
            r = s.post('https://api.fitbit.com/oauth2/token', data=data, headers=headers, proxies=proxies, timeout=10)
            access_token = ast.literal_eval(r.text)['access_token']
            user_id = ast.literal_eval(r.text)['user_id']
            #//////////////#
            ## DELEGATE TOKEN REQUEST ##
            ## DELEGATE TOKEN REQUEST ##
            headers = {
                "Host": "api.fitbit.com",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0",
                "Accept": "application/json, text/javascript, */*; q=0.01",
                "Accept-Language": "en",
                "Accept-Encoding": "gzip, deflate, br",
                "Referer": "https://accounts.fitbit.com/clienthandler",
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                "Authorization": "Bearer " + access_token,
                "Origin": "https://accounts.fitbit.com",
                "Connection": "keep-alive",
                "TE": "Trailers"
            }
            data = "grant_type=delegate_token&client_id=228TQD"
            r = s.post('https://api.fitbit.com/oauth2/delegate', data=data, proxies=proxies, timeout=10, headers=headers)
            delegate_token = r.text[11:][:-2].split(",")[0].split(":")[1].strip('"')
            data = "token=" + delegate_token + "&client_id=228TQF"
            headers = {
                "Host": "api.fitbit.com",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0",
                "Accept": "application/json, text/javascript, */*; q=0.01",
                "Accept-Language": "en-US,en;q=0.5",
                "Accept-Encoding": "gzip, deflate, br",
                "Referer": "https://accounts.fitbit.com/clienthandler",
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                "Origin": "https://accounts.fitbit.com",
                "Connection": "keep-alive",
                "TE": "Trailers"
            }
            r = s.post('https://api.fitbit.com/oauth2/delegate/token', data=data, proxies=proxies, timeout=10, headers=headers)
            delegate_token = re.search('{"result":{"access_token":"(.+?)",', r.text).group(1)
            #//////////////#
            
            
            headers = {
                'Host': 'web-api.fitbit.com',
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0',
                'Accept': 'application/json, text/javascript, */*; q=0.01',
                'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
                'Accept-Language': 'en',
                'Accept-Encoding': 'gzip, deflate, br',
                'Referer': 'https://www.fitbit.com/,',
                'Accept-Locale': 'en_US',
                'Authorization': 'Bearer '+ access_token,
                'Origin': 'https://www.fitbit.com',
                'Connection': 'keep-alive'
                
                }
            if country == 'GB' :
                data = 'locale=en_GB&timezone=Europe/London&foodsLocale=en_GB&country=GB&'
            elif country == 'DE' :
                data = 'locale=de_DE&timezone=Europe/Berlin&foodsLocale=de_DE&country=DE&'
            elif country == 'FR' :
                data = 'locale=fr_FR&timezone=Europe/Paris&foodsLocale=fr_FR&country=FR&'
            elif country == 'ES' :
                data = 'locale=es_ES&timezone=Europe/Madrin&foodsLocale=es_ES&country=ES&'
            r = s.post('https://api.fitbit.com/1/user/' + user_id + '/profile.json', data=data, proxies=proxies, timeout=10, headers=headers)