<p><strong>(2017年2月)</strong>大多数答案(包括OP中的代码)现在已经过时,因为<a href="https://developers.googleblog.com/2012/04/changes-to-deprecation-policies-and-api.html" rel="nofollow noreferrer">ClientLogin authentication was deprecated</a>早在2012年(!),和<a href="http://developers.google.com/gdata/docs/directory" rel="nofollow noreferrer">GData APIs</a>是上一代googleapi。虽然并不是所有的gdataapi都被弃用,但是<a href="http://developers.google.com/api-client-library/python/apis" rel="nofollow noreferrer">all <strong>newer</strong> Google APIs</a>do<strong>not</strong>使用<a href="http://developers.google.com/gdata" rel="nofollow noreferrer">the Google Data protocol</a>,包括最新的<a href="http://developers.google.com/sheets" rel="nofollow noreferrer">Google Sheets API</a>(v4),它比旧的API版本更强大和灵活。在</p>
<p>但是,请注意,Sheets API主要用于以编程方式访问电子表格操作和功能(格式化单元格、单元格验证、调整列大小、创建图表、透视表等),但是要执行<strong>文件级<strong>访问</strong>,例如导出到XLS(X),请改用<a href="http://developers.google.com/drive" rel="nofollow noreferrer"><strong>Google Drive API</strong></a>。使用API的驱动器示例:</p>
<ul>
<li>将Google工作表导出为CSV(<a href="http://wescpy.blogspot.com/2016/07/exporting-google-sheet as-csv.html" rel="nofollow noreferrer">blog post</a>)</li>
<li>“穷人的纯文本到PDF”转换器(<a href="http://wescpy.blogspot.com/2015/12/google-drive-uploading-downloading.html" rel="nofollow noreferrer">blog post</a>)(*)</li>
</ul>
<p>(*)-TL;DR:将纯文本文件上载到驱动器,导入/转换为Google Docs格式,然后将该文档导出为PDF。上面的文章使用了driveapiv2;<a href="http://wescpy.blogspot.com/2015/12/migrating-to-new-google-drive-api-v3.html" rel="nofollow noreferrer">this follow-up post</a>描述了将其迁移到driveapiv3,这里是一个<a href="http://googledevelopers.blogspot.com/2016/01/google-drive-uploading-downloading.html" rel="nofollow noreferrer">developer video</a>组合了两个“穷人的转换器”帖子。在</p>
<p>该操作的解决方案是执行与上面“将Google工作表导出为CSV”帖子中相同的操作,但将export MIMEtype从<code>text/csv</code>更改为<code>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</code>。有关驱动器的其他导入/导出格式,请参见<a href="https://stackoverflow.com/a/38406284/305689">this related question SO answer</a>以及<a href="http://developers.google.com/drive/v3/web/manage-downloads" rel="nofollow noreferrer">downloading files from Drive docs page</a>。在</p>
<p>要了解更多关于如何在Python中使用googleapi的信息,请查看<a href="http://wescpy.blogspot.com" rel="nofollow noreferrer">my blog</a>以及我正在制作的各种Google开发人员视频(<a href="http://youtube.com/playlist?list=PLOU2XLYxmsILOIxBRPPhgYbuSslr50KVq" rel="nofollow noreferrer">series 1</a>和<a href="http://youtube.com/playlist?list=PLOU2XLYxmsIJJFx_MVCQJ7eWF3gDxkl" rel="nofollow noreferrer">series 2</a>)。在</p>