Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Google Spreadsheets to Pandas DataFrame in IPython Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theseatoms

This comment has been minimized.

Show comment
Hide comment
@theseatoms

theseatoms Aug 31, 2016

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

theseatoms commented Aug 31, 2016

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

This comment has been minimized.

Show comment
Hide comment
@kervel

kervel 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"])

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