googleapi的高级python接口

googleA的Python项目详细描述


谷歌API

这是一个python包,它处理Google服务的所有工作,包括googledrive、googlesheet和Gmail。它是Google API的高级接口。直接使用googleapi的缺点是它的文档是用python2.x编写的,这使得它很难理解。在

要使用googleapi,第一步是获得凭证.json'. 最简单的方法是访问Google Drive API Quickstart,然后单击“步骤1:打开驱动器API”部分中的Enable the Drive API按钮。那么沃利娅,给你!不需要处理项目,服务帐户等

这个包使用Drive API v3Google Sheets API v4Gmail API v1。在

安装

pip install googleAPI

依赖关系

  • googleapi python客户端
  • google-auth-httplib2
  • 谷歌认证oauthlib

文件

凭证

每个API都需要凭据。因此,GoogleCredential()是所有其他类的基类。在

注意:除非您想编写自定义函数,否则可以跳过此部分。

假设我们想获得Google驱动器凭证,其中包含编写定制函数的所有范围。在

# Step 1: import the modulefromgoogleAPI.credentialimport*# Step 2: Instance `GoogleCredential()` classgc=GoogleCredential()# Step 3: Get credential# `credential_path` is the place where 'credentials.json' is stored.# There will be a prompt web page that will download the 'token.pickle'# into `credential_path`.creds=gc.credential(credential_path='',credential_scopes=['https://www.googleapis.com/auth/drive'])

参数credential_scopes是必需的。对于您可以选择的所有范围,请访问OAuth 2.0 Scopes for Google APIs。在

GoogleDrive

googledrive是一个云存储,您可以在其中存储文件和文件夹。GoogleDrive()允许您搜索文件ID、获取文件元数据、下载文件等

假设我们想从Google驱动器下载一个.csv文件。在

^{pr2}$

GoogleSheet

假设我们要下载一个名为Google Sheet 1的GoogleSheet作为microsoftexcel文件Google Sheet 1.xlsx。在

# Step 1: import the modulefromgoogleAPI.sheetimport*# Step 2: Instance `GoogleSheet` class with credentialgs=GoogleSheet(credential_path='')# Step 3: Find the Google Sheet ID using spreadsheet name# The result of the `GoogleSheet.search_spreadsheet()` is# saved in a list inside a dictionary in line with the# `GoogleDrive.search_files()`spreadsheet_id=gs.search_spreadsheet("Google Sheet 1")["Google Sheet 1"][0]# Step 4: Download the Google Sheetgs.download_spreadsheet(spreadsheet_id,save_as="Google Sheet 1.xlsx")

假设我们已经有了电子表格ID,我们只想得到这些值 从特定的页Sheet1。在

values=gs.get_values(spreadsheet_id,range_="'Sheet1'")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java根据选择随机设置图标   java如何将Android Studio与本地服务器数据库SQL server 2008连接?   java在点击鼠标后绘制一个椭圆形   java选项窗格相对于其父项的位置   java如何在Android中的switch case中使用String[]输入?   安卓无法从“15.0.1”确定java版本   如果满足特定条件,java是否重置计时器?   java是一个实体类,可以在OOAD中返回其他实体实例吗?   bash将对jar文件| cut | awk和java程序的调用集成到一个统一进程中   Spring安全更新身份验证成功时的最后登录日期   数据库身份验证中基于Java控制台的客户端服务器登录应用程序错误   java Selenium junit测试失败,驱动程序过早获取URL   java LibGdx多点触摸事件混淆   带扫描仪的java打印空间   来自旧版应用程序的java springcloudsleuth头   java如何实现模板设计模式?   java如何比较具有多个值的键的两个映射?   读取时R中的java MemoryError。xlsx