Google云端硬盘API,正在上传文件[Python] [英] Google Drive API, uploading file [Python]

查看:67
本文介绍了Google云端硬盘API,正在上传文件[Python]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用API​​将备份从服务器上传到我的google驱动器.授权顺利通过,文件已上传,但文件未出现在列表中.代码:

I'm use API for upload my backup from server to my google drive. Authorization passed without problems and file is uploaded, but the file does not appear in the list. Code:

import httplib2
import pprint
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.http import MediaFileUpload

f = file('privatekey.p12', 'rb')
key = f.read()
f.close()

credentials = SignedJwtAssertionCredentials('1234567890@developer.gserviceaccount.com', key, scope='https://www.googleapis.com/auth/drive')
http = httplib2.Http()
http = credentials.authorize(http)

drive_service = build('drive', 'v2', http=http)

media_body = MediaFileUpload('/path/to/file/document.txt', mimetype='text/plain', resumable=True)
body = {
    'title': 'My document',
    'description': 'A test document',
    'mimeType': 'text/plain'
}


file = drive_service.files().insert(body=body, media_body=media_body).execute()
pprint.pprint(file)


来自api的响应:


Response from 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驱动器中搜索我的文档",您就会找到此上传的文件

Just search for My document in your google drive , you will find this uploaded files

这篇关于Google云端硬盘API,正在上传文件[Python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆