谷歌硬盘API,上传文件[Python]

谷歌硬盘API,上传文件[Python],python,api,google-drive-api,Python,Api,Google Drive Api,我正在使用API将备份从服务器上传到谷歌硬盘。授权顺利通过,文件已上载,但文件未显示在列表中。 代码: api的回应: {u'alternateLink': u'https://docs.google.com/file/d/0B-FWSwzP0SeyamY1MXFIMmFDZWc/edit?usp=drivesdk', u'appDataContents': False, u'copyable': True, u'createdDate': u'2014-01-04T14:41:19.1

我正在使用API将备份从服务器上传到谷歌硬盘。授权顺利通过,文件已上载,但文件未显示在列表中。 代码:


api的回应:

{u'alternateLink': u'https://docs.google.com/file/d/0B-FWSwzP0SeyamY1MXFIMmFDZWc/edit?usp=drivesdk',
 u'appDataContents': False,
 u'copyable': True,
 u'createdDate': u'2014-01-04T14:41:19.108Z',
 u'description': u'A test document',
 u'downloadUrl': u'https://doc-0c-6s-docs.googleusercontent.com/docs/securesc/376up7hhina7i2kr3lb8jjr3i1qgs9i8/hbgdu1q3abhdnhdr75jrpjohg4aphvci/1388844000000/08619299632362135867/08619299632362135867/0B-FWSwzP0SeyamY1MXFIMmFDZWc?h=16653014193614665626&e=download&gd=true',
 u'editable': True,
 u'etag': u'"G9loKy74Mg0FQ-YRqtCj_yTTrpg/MTM4ODg0NjQ3OTAwMw"',
 u'fileExtension': u'',
 u'fileSize': u'5',
 u'iconLink': u'https://ssl.gstatic.com/docs/doclist/images/icon_10_text_list.png',
 u'id': u'0B-FWSwzP0SeyamY1MXFIMmFDZWc',
 u'kind': u'drive#file',
 u'labels': {u'hidden': False,
             u'restricted': False,
             u'starred': False,
             u'trashed': False,
             u'viewed': True},
 u'lastModifyingUser': {u'displayName': u'1234567890@developer.gserviceaccount.com',
                        u'isAuthenticatedUser': True,
                        u'kind': u'drive#user',
                        u'permissionId': u'08619299632362135867'},
 u'lastModifyingUserName': u'1234567890@developer.gserviceaccount.com',
 u'lastViewedByMeDate': u'2014-01-04T14:41:19.003Z',
 u'md5Checksum': u'ad0234829205b9033196ba818f7a872b',
 u'mimeType': u'text/plain',
 u'modifiedByMeDate': u'2014-01-04T14:41:19.003Z',
 u'modifiedDate': u'2014-01-04T14:41:19.003Z',
 u'originalFilename': u'My document',
 u'ownerNames': [u'1234567890@developer.gserviceaccount.com'],
 u'owners': [{u'displayName': u'1234567890@developer.gserviceaccount.com',
              u'isAuthenticatedUser': True,
              u'kind': u'drive#user',
              u'permissionId': u'08619299632362135867'}],
 u'parents': [{u'id': u'0AOFWSwzP0SeyUk9PVA',
               u'isRoot': True,
               u'kind': u'drive#parentReference',
               u'parentLink': u'https://www.googleapis.com/drive/v2/files/0AOFWSwzP0SeyUk9PVA',
               u'selfLink': u'https://www.googleapis.com/drive/v2/files/0B-FWSwzP0SeyamY1MXFIMmFDZWc/parents/0AOFWSwzP0SeyUk9PVA'}],
 u'quotaBytesUsed': u'5',
 u'selfLink': u'https://www.googleapis.com/drive/v2/files/0B-FWSwzP0SeyamY1MXFIMmFDZWc',
 u'shared': False,
 u'title': u'My document',
 u'userPermission': {u'etag': u'"G9loKy74Mg0FQ-YRqtCj_yTTrpg/ebrUqOkKZ6bmVEtr5zEJa5EOB38"',
                     u'id': u'me',
                     u'kind': u'drive#permission',
                     u'role': u'owner',
                     u'selfLink': u'https://www.googleapis.com/drive/v2/files/0B-FWSwzP0SeyamY1MXFIMmFDZWc/permissions/me',
                     u'type': u'user'},
 u'webContentLink': u'https://docs.google.com/uc?id=0B-FWSwzP0SeyamY1MXFIMmFDZWc&export=download',
 u'writersCanShare': True}

只需在您的google drive中搜索我的文档,您就会在drive v3中找到这些上载的文件,我们可以使用创建功能上载:

A = service.files().create(media_body = 'pig.png',body = {'name':'pig'}).execute()
虽然我已经尝试过,但这只适用于媒体文件类型

API链接:


您说文件已上载,是指您使用浏览器在驱动器中看到它?我问,因为我不知道你所说的“没有出现在列表中”是什么意思。哪个名单?此外,正如我所说,为什么不使用?不,我很抱歉,在谷歌硬盘中没有使用浏览器查看文件。但API返回带有文件链接的“ok response”,而此文件不可用。好的,我无法帮助您解决此特定问题,但我仍然建议您使用或至少尝试PyDrive。我很确定它会解决你的问题。你正在使用一个服务帐户,所以文件在这个帐户的驱动器中。如果你想看到它,你应该给你的用户写/读权限,然后它会出现在你的“与我共享”驱动器文件夹中。这段代码对我来说很好。刚刚在SignedJwtAssertionCredentials中传递了第四个参数user_email(用于我们要上载文件的驱动器的用户)。
A = service.files().create(media_body = 'pig.png',body = {'name':'pig'}).execute()