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访问方法   Javalog4j不读取它的log4j。属性文件   雅加达ee通过Java(web应用程序)使用iText/任何其他使用现成数据的库生成PDF报告   lua使用java阅读TeamSpeak 3消息   将日期转换为BST java   java Spring引用ProxyFactoryBean中带有ref的protoyype bean   如何使java只打印一条带有if语句的消息   java如何通过JavaMail从雅虎服务器发送电子邮件?   使用百分比和BigDecimal的java测试   java如何对字符串数组排序   java验证器+MVC+REST::更新问题   java如何阻止eclipse如此频繁地挂起?   java从AsyncTask(片段内)访问TextView   IDEJava:制作可调整大小和拖动的组件