我希望有人能提供帮助。
我们一直在使用 Google 的“保存到云端硬盘”按钮 API 第 3 版将我们系统生成的文档保存到用户的云端硬盘。这在上周停止了一段时间。
JS控制台抛出的错误是:
Uncaught ReferenceError: _createSaveToDriveWidgetApplication is not defined
at https://drive.google.com/savetodrivebutton?usegapi=1&src=(redacted URL)&filename=My%20Statement.pdf&sitename=My%20Company%20Name&origin=https%3A%2F%2F(redacted URL)&gsrc=3p&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en_GB.sedaY3Dv4HE.O%2Fam%3DwQE%2Fd%3D1%2Fct%3Dzgms%2Frs%3DAGLTcCO2t4glYwUJ-eH43TAA_offcn6l6Q%2Fm%3D__features__
所以我使用演示源从头开始设置 found here在谷歌的 API 文档上。
我的测试源代码是这样的:
<!DOCTYPE html>
<html>
<head>
<title>Save to Drive Demo: Explicit Render</title>
<link rel="canonical" href="https://(redacted)">
<script src="https://apis.google.com/js/platform.js"></script>
<script>
window.___gcfg = {
parsetags: 'explicit'
};
</script>
</head>
<body>
<a href="javascript:void(0)" id="render-link">Render the Save to Drive button</a>
<div id="savetodrive-div"></div>
<script>
function renderSaveToDrive() {
gapi.savetodrive.render('savetodrive-div', {
src: 'https://(redacted)/go.php',
filename: 'My Statement.pdf',
sitename: 'My Company Name'
});
}
document.getElementById('render-link').addEventListener('click', renderSaveToDrive);
</script>
</body>
</html>
编辑的文本是 URLS,两者完全相同的协议(protocol)、主机、域和端口。此外,正在检索的内容开始提供以下响应 header :
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Range
Access-Control-Expose-Headers: Cache-Control, Content-Encoding, Content-Range
即使我不需要 Origin header ,因为此处未使用或不需要 CORS。
我在 MAC 和 Windows 上尝试过 Chrome、Safari、Firefox,结果总是一样的——当调用 gapi.savetodrive.render 时,它停止并出现错误:
Uncaught ReferenceError: _createSaveToDriveWidgetApplication is not defined
我真的不知道还能做什么,所以我在这里查询。我用 Google 搜索了该错误消息,但确实找不到任何相关信息。
最佳答案
这似乎是一个错误。
Save to Drive添加到 HTML 文档时按钮未显示。相反,控制台中会显示以下错误:
Uncaught ReferenceError: _createSaveToDriveWidgetApplication is not defined
在过去的几天里,问题跟踪器中至少报告了两次:
- Google Drive - "Save To Drive" - Widget button not loading or displaying correctly
- Bug with "save to drive " button
这些问题中的第一个已经引起了一些关注:目前有 3 人对其加注星标,并且已由 Google 内部报告(参见 comment #4):
Thank you for filing this report, I was able to reproduce the behaviour so have forwarded it internally.
对于受此影响的任何人,我建议给这个问题加注星标,以提高它的知名度。
关于javascript - Google Save To Drive API v3 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65958472/