Comments (9)
Any updates on this ? We still point to oauth2client
instead of google-auth
in most of our quickstarts.
from python-samples.
This answer on Stack Overflow worked for me.
Please note that there are many more samples than just Sheets which are using oauth2client, namely:
- admin_sdk/directory/quickstart.py
- admin_sdk/reports/quickstart.py
- admin_sdk/reseller/quickstart.py
- apps_script/execute/execute.py
- apps_script/quickstart/quickstart.py
- calendar/quickstart/quickstart.py
- classroom/quickstart/quickstart.py
- drive/activity-v2/quickstart.py
- drive/activity/quickstart.py
- drive/driveapp/main.py
- drive/quickstart/quickstart.py
- events/next18/qbr_tool.py
- gmail/quickstart/quickstart.py
- people/quickstart/quickstart.py
- sheets/quickstart/quickstart.py
- sheets/snippets/base_test.py
- slides/quickstart/quickstart.py
- slides/snippets/base_test.py
- tasks/quickstart/quickstart.py
- vault/quickstart/quickstart.py
from python-samples.
I've converted the sheets quickstart as a proof of concept in #60. Any comments about the token storage before I convert all samples?
from python-samples.
If I understand correctly, to migrate to google-auth
, just replace all code up to the service =
with this and we're good?
NOTE: as @wamcvey pointed out, credentials.json stores service account key
in this code rather than oauth 2.0 client
data (in the deprecated quickstart).
from googleapiclient.discovery import build
import google.auth
AUTH_FILE_PATH = 'tmp/credentials.json'
# <If storing credentials in an env variable>
if not os.path.isfile(AUTH_FILE_PATH):
with open(AUTH_FILE_PATH, 'w') as outfile:
outfile.write(os.environ['GOOGLE_AUTH_PART_1'])
outfile.write(os.environ['GOOGLE_AUTH_PART_2']) # Due to env variable 2048 char limit
# </If storing credentials in an env variable>
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = AUTH_FILE_PATH
google.auth.default()
service = build('sheets', 'v4')
from python-samples.
Can someone make a PR to fix the Sheets quickstart?
- https://developers.google.com/sheets/api/quickstart/python
- https://github.com/gsuitedevs/python-samples/tree/master/sheets/quickstart
from python-samples.
FWIW, the Drive API quickstart still references the deprecated oauth2client flow.
https://developers.google.com/drive/api/v3/quickstart/python
Also, the recommendation made bi @Elijas doesn't seem to be sufficient. The GOOGLE_APPLICATION_CREDENTIALS file that is read by google.auth.default() is expecting a top-level type
value set to either authorized_user
or service_account
. The JSON file that is produced as part of the quickstart (and stored in credentials.json
, has no type
key.
from python-samples.
FWIW, the Drive API quickstart still references the deprecated oauth2client flow.
https://developers.google.com/drive/api/v3/quickstart/pythonAlso, the recommendation made bi @Elijas doesn't seem to be sufficient. The GOOGLE_APPLICATION_CREDENTIALS file that is read by google.auth.default() is expecting a top-level
type
value set to eitherauthorized_user
orservice_account
. The JSON file that is produced as part of the quickstart (and stored incredentials.json
, has notype
key.
Thanks for pointing it out! I haven't looked to using OAuth 2.0
but the relevant section appears to be present in the docs, and could be used to authenticate with the OAuth
credentials
from python-samples.
Ok so with #60 merged, all the basic examples have been converted.
There's just a few left that are slightly more exotic:
- apps_script/execute/execute.py
- drive/driveapp/main.py
- events/next18/qbr_tool.py
- sheets/snippets/base_test.py
- slides/snippets/base_test.py
from python-samples.
form_service = discovery.build('forms', 'v1', http=creds.authorize(
Http()), discoveryServiceUrl=DISCOVERY_DOC, static_discovery=False)
This results in the error UnknownApiNameOrVersion: name: forms version: v1
Is forms
API different that other APIs such as calendar
or drive
?
from python-samples.
Related Issues (20)
- Is it possible to retrieve all the data from a Google Form?
- DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials HOT 1
- Phyton Samples
- How to see the progress of files which is getting uploaded
- [SyncRepoSettings bot] - Invalid config file
- Add Forms file upload Code and textquestions validation code examples.
- ls
- conda is not recognised as an internal command HOT 1
- permission error
- Conda not recognised as internal comman
- Google python
- How to send emails using group sending single display
- Sample does not provide working authentication
- Error on authorization on python linux.
- Authentication Error. HOT 1
- Query: contains doesn't work with long prefix that end with 1
- Upload image as bytes.
- Downloading Excel file with Google Drive API doesn't bring lastest modification/version HOT 1
- docs_mail_merg Issues HOT 1
- google drive OAuth does not work HOT 1
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 python-samples.