Code Monkey home page Code Monkey logo

Comments (9)

ocervell avatar ocervell commented on June 7, 2024 1

Any updates on this ? We still point to oauth2client instead of google-auth in most of our quickstarts.

from python-samples.

slokhorst avatar slokhorst commented on June 7, 2024 1

This answer on Stack Overflow worked for me.

Please note that there are many more samples than just Sheets which are using oauth2client, namely:

from python-samples.

slokhorst avatar slokhorst commented on June 7, 2024 1

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.

Elijas avatar Elijas commented on June 7, 2024

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.

grant avatar grant commented on June 7, 2024

Can someone make a PR to fix the Sheets quickstart?

from python-samples.

wamcvey avatar wamcvey commented on June 7, 2024

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.

Elijas avatar Elijas commented on June 7, 2024

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.

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.

slokhorst avatar slokhorst commented on June 7, 2024

Ok so with #60 merged, all the basic examples have been converted.

There's just a few left that are slightly more exotic:

from python-samples.

bngsudheer avatar bngsudheer commented on June 7, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.