简体   繁体   English

如何从Chrome扩展程序下载公开的Google云端硬盘文件?

[英]How to download public Google Drive file from Chrome Extension?

I have public Google Drive file like this one: https://docs.google.com/uc?id=0B8G77eDgeMdwMmkwcnA5eUV2M0U&export=download 我有像这样的公开Goog​​le云端硬盘文件: https//docs.google.com/uc?id = 0B8G77eDgeMdwMmkwcnA5eUV2M0U&export = download

I want to download that file from a Chrome Extension. 我想从Chrome扩展程序下载该文件。

I have added these urls to the "permissions" element in the extension manifest (there are some redirects when trying to download the file and I tried to add them all): "https://*.docs.googleusercontent.com/"," https://docs.google.com/ "," http://docs.google.com/ "," https://accounts.google.com/ ", " https://www.google.com/ " 我已将这些网址添加到扩展程序清单中的“permissions”元素中(尝试下载文件时有一些重定向,我尝试将它们全部添加):“https://*.docs.googleusercontent.com/”, “ https://docs.google.com/ ”, “ http://docs.google.com/ ”, “ https://accounts.google.com/ ”,“ https://www.google.com/

When I try to download the file Chrome returns this error: 当我尝试下载该文件时,Chrome会返回以下错误:

XMLHttpRequest cannot load https://docs.google.com/nonceSigner?nonce=s35adai1lp052&continue=https://do…Ddownload%26h%3D16653014193614665626&hash=inkfclb76vcru6uuoqkfp274hk5joqk9. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

It seems I have already allowed downloads for the url in question. 我似乎已经允许下载这个网址了。

If I add the <all_urls> permission the download succeeds. 如果我添加<all_urls>权限,则下载成功。

Any idea what permission I need to add? 知道我需要添加哪些权限? Thanks in advance. 提前致谢。

Using for instance wget and looking at the reported redirections, you can see that the last host is something like: 使用例如wget并查看报告的重定向,您可以看到最后一个主机是这样的:

doc-0c-80-docs.googleusercontent.com

The first part is probably variable, and wildcards in the host part of the URL can only match an entire part of the hostname. 第一部分可能是变量,URL的主机部分中的通配符只能匹配主机名的整个部分。 So you should add the following to your match patterns: 所以你应该在你的匹配模式中添加以下内容:

*.googleusercontent.com

You need at least the following minimum to access Drive files: 您至少需要以下最低要求才能访问云端硬盘文件:

  • *://drive.google.com/* *://drive.google.com/*
  • *://*.googleusercontent.com/* *://*.googleusercontent.com/*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM