Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- from googleapiclient.discovery import build
- from httplib2 import Http
- from oauth2client import file, client, tools
- import gspread
- # If modifying these scopes, delete the file token.json.
- SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
- # The ID and range of a sample spreadsheet.
- SAMPLE_SPREADSHEET_ID = '1hhgc5eLcW7GnOaWUO9W6tXcg1axmrftSTvKjU90E7o0'
- SAMPLE_RANGE_NAME = 'A1:E1'
- def main():
- """Shows basic usage of the Sheets API.
- Prints values from a sample spreadsheet.
- """
- # The file token.json stores the user's access and refresh tokens, and is
- # created automatically when the authorization flow completes for the first
- # time.
- store = file.Storage('token.json')
- creds = store.get()
- if not creds or creds.invalid:
- flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
- creds = tools.run_flow(flow, store)
- service = build('sheets', 'v4', http=creds.authorize(Http()))
- # Call the Sheets API
- sheet = service.spreadsheets()
- result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
- range=SAMPLE_RANGE_NAME).execute()
- values = result.get('values', [])
- if not values:
- print('No data found.')
- else:
- print(values)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement