相关疑难解决方法(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 xlsx 电子表格 / Google Drive 权限也被阻止

我有一个 Google Apps 脚本,我目前正在使用它来成功打开 Google 表格电子表格(与我的帐户共享只读)并执行一些阅读功能。

我收到了另一个电子表格,我想在上面运行类似的流程。如果我尝试:( SpreadsheetApp.openById("_______")在另一张纸上有效),我会得到Exception: Service Spreadsheets failed while accessing document with id _____"这张纸。这个电子表格实际上是 Google Drive 上的一个 xlsx(但它似乎仍然可以在 Google 表格中打开)而不是原生的 Google 表格,所以我想也许这就是问题所在......?

所以现在我尝试使用DriveApp.getFileById("____"). 但是现在我收到了一个授权请求,允许我的脚本访问 Google Drive。当我授权时,我得到:

此应用已被阻止
此应用试图访问您 Google 帐户中的敏感信息。为确保您的帐户安全,Google 阻止了此访问。

我还没有找到解决这个问题的方法。我使用的是私人 Google 帐户,而不是使用公司的应用程序。有任何想法吗?

google-sheets google-apps-script google-drive-api google-sheets-api

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