3

I am trying to access my google Spreadsheet using oauth2 using the gspread Python Library.I am new to Oauth2 and understand its benefits.But I am unable to use it.So far I have visited https://code.google.com/apis/console/ and generated CLIENT ID,SECRET and REDIRECT URI.

credentials = SignedJwtAssertionCredentials('developer@example.com', SIGNED_KEY, scope)

According to the Gspread Docs I will need a SIGNED_KEY object.How do I get that?

An example will be very helpful.

Dave Smith
  • 103
  • 7

1 Answers1

3

In the developer console, (https://console.developers.google.com) go to APIs & auth > Credentials and click Create new Client ID, then choose Service Account. Your browser should download a .p12 file. Now convert it to a PEM for GAE by doing this in the command line:

openssl pkcs12 -passin pass:notasecret -in privatekey.p12 -nocerts -passout pass:notasecret -out key.pem
openssl pkcs8 -nocrypt -in key.pem -passin pass:notasecret -topk8 -out privatekey.pem

You then have to move the PEM to your app directory, open it in your app code and then use it as the second arg in SignedJwtAssertionCredentials

Also make sure the app.yaml libraries section includes pycrypto

libraries:
- name: pycrypto
  version: "2.6"

I got this from someone's very helpful tutorial

Ryan
  • 3,555
  • 1
  • 22
  • 36
  • Do I need to register an app engine application for this?I am not planning to port this application to GAE. This will be running in my personal computer. – Dave Smith Nov 19 '14 at 09:02
  • In the dev console, it looks like you at least need to create a new project, and then create a service account/activate the APIs you're looking to use. I don't know if there's another way to get a .p12 file from Google except by creating a Service account. – Ryan Nov 19 '14 at 09:11
  • Just tried this and seems like Google returns a json file with the credentials now by default...however, once the client id is created, a button to download a .p12 file appears – Abel Molina Mar 21 '15 at 12:27