相关疑难解决方法(0)

如何使用 Python 和 Drive API v3 从 Google Drive 下载文件

我尝试使用 python 脚本将文件从 Google Drive 下载到本地系统,但在运行 Python 脚本时遇到“禁止”问题。脚本如下:

import requests

url = "https://www.googleapis.com/drive/v3/files/1wPxpQwvEEOu9whmVVJA9PzGPM2XvZvhj?alt=media&export=download"

querystring = {"alt":"media","export":"download"}

headers = {
    'Authorization': "Bearer TOKEN",

    'Host': "www.googleapis.com",
    'Accept-Encoding': "gzip, deflate",
    'Connection': "keep-alive",
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.url)
#
import wget
import os
from os.path import expanduser


myhome = expanduser("/home/sunarcgautam/Music")
### set working dir
os.chdir(myhome)

url = "https://www.googleapis.com/drive/v3/files/1wPxpQwvEEOu9whmVVJA9PzGPM2XvZvhj?alt=media&export=download"
print('downloading ...')
wget.download(response.url)
Run Code Online (Sandbox Code Playgroud)

在这个脚本中,我遇到了禁止的问题。我在脚本中做错了什么吗?

我还尝试了在 Google 开发者页面上找到的另一个脚本,如下所示:

import auth
import httplib2
SCOPES = "https://www.googleapis.com/auth/drive.scripts"
CLIENT_SECRET_FILE = "client_secret.json"
APPLICATION_NAME = "test_Download"
authInst = auth.auth(SCOPES, …
Run Code Online (Sandbox Code Playgroud)

python google-drive-api

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-drive-api ×1

python ×1