gpt4 book ai didi

python - 如何使用 http 请求从 google drive 获取列表文件?

转载 作者:可可西里 更新时间:2023-11-01 17:18:03 24 4
gpt4 key购买 nike

如何使用访问 token 获取文件列表?我阅读了 doc google drive,但我不知道如何编写列出文件的请求。我的例子:

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 检索文件列表。

如果我对你的问题的理解是正确的,那么这个修改怎么样?

修改点:

  • 当它使用headers时,请使用{"Authorization": "Bearer "+ accessToken}
  • 您还可以使用访问 token 作为查询参数。

您可以根据自己的情况选择以下2种模式。

模式一:使用 header

import requests
access_token = "#####"
headers = {"Authorization": "Bearer " + access_token}
r = requests.get('https://www.googleapis.com/drive/v3/files', headers=headers)
print(r.text)

模式二:使用查询参数

import requests
access_token = "#####"
r = requests.get('https://www.googleapis.com/drive/v3/files?access_token=' + access_token)
print(r.text)

备注:

  • 这个修改后的脚本假设如下。
    • Drive API 已在 API 控制台启用。
    • 检索文件列表的范围包含在访问 token 的范围内。

引用资料:

如果我误解了你的问题,我很抱歉。

关于python - 如何使用 http 请求从 google drive 获取列表文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53237551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com