def withings_connect(client, oauth_verifier, oauth_token, oauth_secret): try: healthdevice = client.health_device except: healthdevice = HealthDevice(client=client) auth = WithingsAuth(WITHINGS_SETTINGS['CONSUMER_KEY'], WITHINGS_SETTINGS['CONSUMER_SECRET'], withings_get_callback_uri()) auth.oauth_token = oauth_token auth.oauth_secret = oauth_secret print(oauth_verifier, oauth_token, oauth_secret) creds = auth.get_credentials(oauth_verifier) try: healthdevice = client.health_device except: healthdevice = HealthDevice(client=client) healthdevice.provider = HealthDevice.ProviderType.WITHINGS.value healthdevice.access_token = creds.access_token healthdevice.refresh_token = '' healthdevice.expires_at = datetime.now() + timedelta(days=365) healthdevice.meta = { 'access_token_secret': creds.access_token_secret, 'user_id': creds.user_id } healthdevice.save() return True
def getWithingsClient(): auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET) authorize_url = auth.get_authorize_url() print "Go to %s allow the app and copy your oauth_verifier" % authorize_url oauth_verifier = raw_input('Please enter your oauth_verifier: ') creds = auth.get_credentials(oauth_verifier) client = WithingsApi(creds) return client
def test_get_credentials(self): """ Make sure the get_credentials function works as expected """ auth = WithingsAuth(self.consumer_key, self.consumer_secret) # Returns an authorized WithingsCredentials object creds = auth.get_credentials('FAKE_OAUTH_VERIFIER') assert isinstance(creds, WithingsCredentials) # Check that the attributes of the WithingsCredentials object are # correct. self.assertEqual(creds.access_token, 'fake_oauth_token') self.assertEqual(creds.access_token_secret, 'fake_oauth_token_secret') self.assertEqual(creds.consumer_key, self.consumer_key) self.assertEqual(creds.consumer_secret, self.consumer_secret) self.assertEqual(creds.user_id, 'FAKEID')
# copied from https://github.com/maximebf/python-withings/blob/master/README.md from withings import WithingsAuth, WithingsApi from settings import CONSUMER_KEY, CONSUMER_SECRET auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET) authorize_url = auth.get_authorize_url() print "Go to %s allow the app and copy your oauth_verifier" % authorize_url oauth_verifier = raw_input('Please enter your oauth_verifier: ') creds = auth.get_credentials(oauth_verifier) client = WithingsApi(creds) measures = client.get_measures(limit=1) print "Your last measured weight: %skg" % measures[0].weight
from withings import WithingsAuth, WithingsApi auth = WithingsAuth("53384734f261f01e1b5e728f36d77242bdf48eef43f76b19786b12eef5866", "b084dd376872378236d3d56191e5de52e3b054d01989551d1464e2d8e7b222") #authorize_url = auth.get_authorize_url() #print "Go to %s allow the app and copy your oauth_verifier" % authorize_url #oauth_verifier = raw_input('Please enter your oauth_verifier: ') creds = auth.get_credentials("IKfIyVSF1KU") client = WithingsApi(creds) measures = client.get_measures(limit=1) print "Your last measured weight: %skg" % measures[0].weight