Reputation: 11
I am trying to use gpread with python to edit google spreadsheets. I followed this tutorial: http://gspread.readthedocs.org/en/latest/oauth2.html When I run my code, it says that there is no module named oauth2client.client. Do I need to install something else to make it work?
Update here is my code:
import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
json_key = json.load(open('GraduationCash-c4b4c0667c75.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
wks = gc.open("Where is the money Lebowski?").sheet1
raw_input()
Also i should mention that I am on windows 8, so those commands are not working. it is still saying that there is no crypto library avalible
Upvotes: 0
Views: 3224
Reputation: 13559
Yes, you must install OAuth client library:
$ pip install --upgrade oauth2client
Of course, you always can install from source, also well:
$ git clone https://github.com/google/oauth2client
$ cd oauth2client
$ python setup.py install
Note After intall if you get a error like "No crypto library available":
$ apt-get install python-openssl
or
$ pip install PyOpenSSL
Upvotes: 2
Reputation: 369
Instead of using SignedJwtAssertionCredentials, I've used GoogleCredentials.
I had success with the following code below. I had to create an account on the Google Developer site here. From there, go to API Manager > Google Apps API > Drive API, then Enable API. Then select Credentials > New Credentials > Service account key. At this point, download the key as JSON and store it somewhere secure. Copy the email address in the JSON file and add it to the sheet you want to access.
import gspread
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
credentials = credentials.create_scoped(['https://spreadsheets.google.com/feeds'])
gs = gspread.authorize(credentials)
sheet = gs.open('Testing').worksheet('Sheet1')
list_of_lists = sheet.get_all_values()
print(list_of_lists)
Upvotes: 2