Skip to content

Instantly share code, notes, and snippets.

@egradman
Last active November 2, 2022 04:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save egradman/3b8140930aef97f9b0e4 to your computer and use it in GitHub Desktop.
Save egradman/3b8140930aef97f9b0e4 to your computer and use it in GitHub Desktop.
Simple Google Spreadsheets to Pandas DataFrame in IPython Notebook
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theseatoms
Copy link

How exactly does one retrieve valid Client ID and Client Secret? I attempted to do so by parsing the JSON returned by "Create Credentials" > "Service Account Key" at the following link?
https://console.developers.google.com/apis/credentials?project=PROJECT-NAME

The JSON file I've retrieved only has the following keys (and the "client_id" is only an integer, with no domain after a hyphen):
private_key
private_key_id
token_uri
auth_provider_x509_cert_url
auth_uri
client_email
client_id
project_id
type
client_x509_cert_url

The following link might be helpful: https://developers.google.com/identity/protocols/application-default-credentials?hl=en_US

Thanks in advance for any clues. If this is a common stumbling block for people, I could add further instructions to the documentation.

TS

@kervel
Copy link

kervel commented Sep 14, 2016

btw, if you are (like us) on python3 with a buggy httplib2 that refuses to connect to a proxy server, the hack below makes oauthlib2 use requests instead of httplib2

class DropInHttplib():
    def __init__(self):
        self.sess = requests.session()

    def request(self, uri, method='GET' , body=None , headers=None):
        resp = None
        if method.lower() == 'get':
            resp = self.sess.get(uri, headers=headers)

        elif method.lower() == 'post':
            resp = self.sess.post(uri,data=body,headers=headers)
        if resp.status_code == 200:
            resp.status = httplib2.http.client.OK
        else:
            resp.status = httplib2.http.client.BAD_REQUEST
        return (resp,resp.text)

then, one can do

httpclient = DropInHttplib()
credentials = oauth2client.tools.run_flow(flow, storage, flags, httpclient)

and we needed to modify the flags so that it would work on a server (where we could not open a browser window)

flags = argparse.ArgumentParser(parents=[oauth2client.tools.argparser]).parse_args(["--noauth_local_webserver"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment