如何通过http请求从Google Drive获取列表文件? [英] How get list files from google drive with http request?

查看:101
本文介绍了如何通过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().
    • 如果我对您的问题的理解是正确的,那么该修改如何?

      If my understanding for your question is correct, how about this modification?

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

      您可以根据自己的情况选择以下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)
      

      注意:

      • 此修改后的脚本假定如下.
        • Drive API已在API控制台上启用.
        • 检索文件列表的范围包含在访问令牌的范围中.
        • 如果我误解了你的问题,对不起.

          If I misunderstand your question, I'm sorry.

          这篇关于如何通过http请求从Google Drive获取列表文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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