Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. from __future__ import print_function
  2. from googleapiclient.discovery import build
  3. from httplib2 import Http
  4. from oauth2client import file, client, tools
  5. import gspread
  6.  
  7. # If modifying these scopes, delete the file token.json.
  8. SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
  9.  
  10. # The ID and range of a sample spreadsheet.
  11. SAMPLE_SPREADSHEET_ID = '1hhgc5eLcW7GnOaWUO9W6tXcg1axmrftSTvKjU90E7o0'
  12. SAMPLE_RANGE_NAME = 'A1:E1'
  13.  
  14. def main():
  15. """Shows basic usage of the Sheets API.
  16. Prints values from a sample spreadsheet.
  17. """
  18. # The file token.json stores the user's access and refresh tokens, and is
  19. # created automatically when the authorization flow completes for the first
  20. # time.
  21. store = file.Storage('token.json')
  22. creds = store.get()
  23. if not creds or creds.invalid:
  24. flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
  25. creds = tools.run_flow(flow, store)
  26. service = build('sheets', 'v4', http=creds.authorize(Http()))
  27.  
  28. # Call the Sheets API
  29. sheet = service.spreadsheets()
  30. result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
  31. range=SAMPLE_RANGE_NAME).execute()
  32. values = result.get('values', [])
  33.  
  34. if not values:
  35. print('No data found.')
  36. else:
  37. print(values)
  38.  
  39. if __name__ == '__main__':
  40. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement