如何通过http请求从Google Drive获取列表文件? [英] How get list files from google drive with http request?
本文介绍了如何通过http请求从Google Drive获取列表文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取带有访问令牌的文件列表?我读了doc google drive,但是我不知道如何写请求列出文件.我的例子:
How I can get files list with access token? I read doc google drive, but i dont know how write requests for listing files. My Example:
rqf = requests.get('https://www.googleapis.com/drive/v3/files', headers=
{"Authorization": access_token})
输出
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
推荐答案
- 您想通过
requests.get()
使用Drive API v3检索文件列表. - You want to retrieve the file list using Drive API v3 by
requests.get()
. - 当它使用
headers
时,请使用{"Authorization":"Bearer" + accessToken}
. - 您还可以将访问令牌用作查询参数.
如果我对您的问题的理解是正确的,那么该修改如何?
If my understanding for your question is correct, how about this modification?
您可以根据自己的情况选择以下2种模式.
You can select the following 2 patterns for your situation.
import requests
access_token = "#####"
headers = {"Authorization": "Bearer " + access_token}
r = requests.get('https://www.googleapis.com/drive/v3/files', headers=headers)
print(r.text)
模式2:使用查询参数
import requests
access_token = "#####"
r = requests.get('https://www.googleapis.com/drive/v3/files?access_token=' + access_token)
print(r.text)
注意:
查看全文