python google drive api_我想使用Drive Api从Google Drive下载文件

in this code :

file_id = '0BwwA4oUTeiV1UVNwOHItT0xfa2M'

request = drive_service.files().get_media(fileId=file_id)

fh = io.BytesIO()

downloader = MediaIoBaseDownload(fh, request)

done = False

while done is False:

status, done = downloader.next_chunk()

print "Download %d%%." % int(status.progress() * 100)

I don't know how to get file_id , I was getting file_id while uploading but now I am not able to figure out how to get file_id of the file which is present on Google Drive.

Ex. if my uploaded file has name A001002.pdf , how can i get file id for this file.

there is some reference online which i am not able to understand.

any help?

解决方案

The file.list method contains a q paramater which is used for searching

Python Guess

"""

Shows basic usage of the Drive v3 API.

Creates a Drive v3 API service and prints the names and ids of the last 10 files

the user has access to.

"""

from __future__ import print_function

from apiclient.discovery import build

from httplib2 import Http

from oauth2client import file, client, tools

# Setup the Drive v3 API

SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'

store = file.Storage('credentials.json')

creds = store.get()

if not creds or creds.invalid:

flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)

creds = tools.run_flow(flow, store)

service = build('drive', 'v3', http=creds.authorize(Http()))

# Call the Drive v3 API

results = service.files().list(

pageSize=10, fields="*").execute()

items = results.get('files', [])

if not items:

print('No files found.')

else:

print('Files:')

for item in items:

print('{0} ({1})'.format(item['name'], item['id']))

Note this example does not show how to add the additional parameter i am still Googling that but i am not a python dev you may know more about how to do that than me.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值