Comments (4)
(1) Create service account (see instructions).
(2) Download key as JSON.
(3) Manage API client access at https://admin.google.com/${DOMAIN}/AdminHome?chromeless=1#OGX:ManageOauthClients
- Add the "Unique ID" from step 1 as the "Client Name"
- Add
https://www.googleapis.com/auth/spreadsheets.readonly
as the scope.
(4) Make sure to impersonate a user, otherwise it will fail:
from __future__ import print_function
from google.oauth2 import service_account
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
def main():
"""Shows basic usage of the Sheets API.
Prints values from a sample spreadsheet.
"""
SERVICE_ACCOUNT_FILE = '/Users/bdealmeida/Downloads/gsheetsdb-2bb6767cc084.json'
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_creds = creds.with_subject('[email protected]')
service = build('sheets', 'v4', credentials=delegated_creds)
# Call the Sheets API
SPREADSHEET_ID = '1hsxoXlOTQzMgNdS4Hp6tg-nVRq8v4Mc7syYZsOHltTk'
RANGE_NAME = 'A2:B3'
result = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID,
range=RANGE_NAME).execute()
values = result.get('values', [])
if not values:
print('No data found.')
else:
print('Name, Major:')
for row in values:
# Print columns A and E, which correspond to indices 0 and 4.
print(row)
if __name__ == '__main__':
main()
from gsheets-db-api.
Based on:
- https://developers.google.com/sheets/api/quickstart/python
- https://developers.google.com/api-client-library/python/auth/service-accounts
from gsheets-db-api.
Scope should be https://spreadsheets.google.com/feeds
instead.
from gsheets-db-api.
^ https://developers.google.com/chart/interactive/docs/spreadsheets
from gsheets-db-api.
Related Issues (14)
- Missing functionality
- Add support for granularity functions HOT 2
- Handle `COUNT(*)` outside of `SELECT` HOT 1
- Insert/update support?
- Open spreadsheet as database, worksheets as tables?
- SqlAlchemy HOT 2
- Getting error: "Connection failed" HOT 2
- In Catalog Mode, be able to specify a table alias
- Can't get time granularity using GSHEET driver in Superset.
- Latest setup tools is breaking the library HOT 1
- Not working with newer moz-sql-parser
- Accessing private gsheets
- Couldn't parse date string 'datetime.date(2022, 3, 25)' with SQLAlchemy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gsheets-db-api.