Search code examples
pythongoogle-apigoogle-api-python-clientgoogle-fitgoogle-client

Googleapiclient python fit api


Is there googleapiclient example or documentation for google fit i can't find any documentation about google fit api for python all example i found is for google drive like

import googleapiclient.discovery
drive = googleapiclient.discovery.build(
  API_SERVICE_NAME, API_VERSION, credentials=credentials)

files = drive.files().list().execute()

Solution

  • The code you have there isn't going to work very well as it appears to be related to Google drive.

    def retrieve_data():
        """
        Run through the OAuth flow and retrieve credentials.
        Returns a dataset (Users.dataSources.datasets):
        https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets
        """
        flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
        authorize_url = flow.step1_get_authorize_url()
        print 'Go to the following link in your browser:'
        print authorize_url
        code = raw_input('Enter verification code: ').strip()
        credentials = flow.step2_exchange(code)
    
        # Create an httplib2.Http object and authorize it with our credentials
        http = httplib2.Http()
        http = credentials.authorize(http)
    
        fitness_service = build('fitness', 'v1', http=http)
    
        return fitness_service.users().dataSources(). \
                  datasets(). \
                  get(userId='me', dataSourceId=DATA_SOURCE, datasetId=DATA_SET). \
                  execute()
    

    Check this file for the full code Getfit.py and make sure you set up your redirect URIs properly