![](/img/trans.png)
[英]How to add new blank row in the middle of text in Google Docs when using gspread module for python?
[英]How to link google account when using gspread and python?
我正在嘗試將gpread與python一起使用以編輯Google電子表格。 我遵循了本教程: http ://gspread.readthedocs.org/en/latest/oauth2.html運行代碼時,它說沒有名為oauth2client.client的模塊。 我需要安裝其他東西才能使其工作嗎?
更新這里是我的代碼:
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()
我還應該提到我在Windows 8上,所以這些命令不起作用。 仍然在說沒有可用的加密庫
是的,您必須安裝OAuth客戶端庫 :
$ pip install --upgrade oauth2client
當然,您總是可以從源代碼安裝,也可以:
$ git clone https://github.com/google/oauth2client
$ cd oauth2client
$ python setup.py install
注意安裝后,如果出現類似“ No可用的密碼庫 ”的錯誤:
$ apt-get install python-openssl
要么
$ pip install PyOpenSSL
我沒有使用SignedJwtAssertionCredentials,而是使用了GoogleCredentials。
我在下面的代碼中取得了成功。 我必須在此處的Google Developer網站上創建一個帳戶。 從那里轉到API管理器> Google Apps API>驅動器API,然后啟用API。 然后選擇“憑證”>“新憑證”>“服務帳戶密鑰”。 此時,將密鑰下載為JSON並將其存儲在安全的地方。 將電子郵件地址復制到JSON文件中,然后將其添加到您要訪問的工作表中。
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.