Google 驱动器表单图像下载时卷曲失败

Curl failing on Google Drive form image download

对不起,我不太熟悉 curl,但我正在尝试使用它下载 Google 驱动器映像。文件下载为 HTML,而不是 jpg。我通过包裹在 Extendscript app.doScript 命令中的 Applescript shell 脚本调用 curl,但我也从终端尝试并收到相同的文件。我遵循了这些说明:

这是我正在使用的完整 Extendscript 代码。

var assetFolderPath = Folder.selectDialog();
var fileName = "/test.jpg";
var front = "https://drive.google.com/uc?export=download&id=";
var root = "google-drive-id#"; //the real id is here instead
var exporturl = front + root;
var ff = File(assetFolderPath + fileName);
var curlCommand = "\"curl -L -o '" + ff.fsName + "' " + "'" + exporturl + "'";
var asCode = 'do shell script ' + curlCommand + '"';
app.doScript(asCode, ScriptLanguage.APPLESCRIPT_LANGUAGE);

提前致谢。

如何使用带有 curl

的驱动器 API 下载文件

您似乎正在尝试使用 files.export 端点下载文件,但是在文档中它说:

Exports a Google Doc to the requested MIME type and returns the exported content.

也就是说,export 端点仅适用于 Google 文档类型,即表格、文档、幻灯片等。

对于所有其他类型的文件,您需要使用 files.get 并在 URL 末尾添加一个 ?alt=media。为此,您需要文件 ID 和您的 oauth 访问令牌。

bash 中的 curl 命令看起来像这样:

curl \
  "https://www.googleapis.com/drive/v3/files/${FILE_ID}?alt=media" \
  --header "Authorization: Bearer ${ACCESS_TOKEN}" \
  --header 'Accept: application/json' \
  --compressed -o $OUTPUT_PATH

用文件 ID、oauth 访问令牌和输出路径替换 ${} 变量。

例如:

curl \
  "https://www.googleapis.com/drive/v3/files/xxxxxxx?alt=media" \
  --header "Authorization: Bearer xxxxxxx" \
  --header 'Accept: application/json' \
  --compressed -o image.jpg

假设选择的 ID 是一个 .jpg 文件,那么在 运行 所在的文件夹中,它将创建一个 image.jpg 图像文件。

您可以在 guide 中找到更多信息。

参考