python gspread 来连接google sheets

在此纪录自己练习的过程。

首先在你的google cloud platform 新增专案

再启用google drive、sheets api
http://img2.58codes.com/2024/20119591OEoJWHIoRt.png

新增凭证
http://img2.58codes.com/2024/20119591xbh4tY0wrR.png

名称自订,角色选project 编辑者
http://img2.58codes.com/2024/20119591FaUSFsddfq.png

把金钥档放在你要的目录

python

我使用gspread这个库

import gspreadfrom oauth2client.service_account import ServiceAccountCredentialsscope = ['https://spreadsheets.google.com/feeds',         'https://www.googleapis.com/auth/drive']credentials = ServiceAccountCredentials.from_json_keyfile_name('yourkey.json', scope)gc = gspread.authorize(credentials)wks = gc.open("your sheets").sheet1

记得要把你的key档里面client_email加入共用者到你的试算表

print(wks.get_all_records())

这样就完成读取google sheets了!


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章