授权 Google 个图表访问私人电子表格
Authorizing Google Charts to access private spreadsheets
我正在尝试使用 Google Apps 脚本创建 Web 应用程序,以使用 Google Charts.
从我的 Google Sheet 查询数据
当 Google Sheet 公开共享时,我已经能够成功查询电子表格,但是由于电子表格包含机密信息,我宁愿使用 authorizations 私下进行查询。
我之所以要使用 Google 图表可视化功能(相对于服务器端电子表格应用程序)是因为查询大型数据集的速度。
我已尝试按照上述文档中的步骤操作。也就是说,创建一个客户端 ID,然后使用 gapi.auth 库对我自己进行身份验证,但我仍然收到错误消息。
当我添加授权库和文档中代码的第一部分时(使用 console.log 只是为了查看它到达的位置):
<script src="https://apis.google.com/js/auth.js?onload=init"></script>
<script>
var clientId = '1234.apps.googleusercontent.com';
var scopes = 'https://spreadsheets.google.com/feeds';
function init() {
console.log("here");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},handleAuthResult);
}
</script>
我收到以下错误:
1289869776-mae_html_user_bin_i18n_mae_html_user.js:41 dropping
postMessage.. was from unexpected window
感谢任何指导。
我能否建议您从使用 Google sheets 改为使用带有 Google sheets 的 firebase 或仅使用 Firebase,然后再使用 Google后端的appscript。
我经常使用 Google 脚本使用来自 Google sheet 的数据更新 Firebase 时出现问题。然后我享受 Firebase 的速度和安全性,以提供超快速的用户体验。
有两个在 appscript 中使用 Firebase 的页面。例子page and the quick start。
此外,我放弃了使用 Google 自己的图表库,开始使用 high charts 或 chartJS,因为它们更易于访问。
由于您是使用 Google Apps Script 创建网络应用程序,因此没有必要 "authorize Google Charts to access private charts" 因为您可以使用 Google Apps Script 服务和方法从电子表格并将它们传递给 Google 图表。
在 Converting from UiApp + Chart Service to Html Service + Google Visualization API 上展示了如何将旧的仪表板示例从 UiApp + 图表服务转换为 HtmlService + Google 可视化 API。这说明了如何创建一个 Google Apps 脚本网络应用程序,该应用程序根据 Google 电子表格数据构建图表,而不 "requiring authorization" 因为它 "implicitly" 由 Google Apps 脚本处理。
从上面link
Two functions cooperate to retrieve the dashboard’s data and display it. As soon as the visualization API is loaded, the sendQuery() function is invoked. Using the google.script.run facility, it sends its request to the server-side getSpreadsheetData() function. This is an asynchronous operation, so two callbacks are provided, a successHandler and a failureHandler. One or the other will receive the result of the server call, depending on the outcome.
H/T 到 jfllmartin, author of an answer to Converting my google dashboard app from the UI service to the HTML service 上面 link 被分享。
相关
- Display Spreadsheet data in Sites with Html Service
我正在尝试使用 Google Apps 脚本创建 Web 应用程序,以使用 Google Charts.
从我的 Google Sheet 查询数据当 Google Sheet 公开共享时,我已经能够成功查询电子表格,但是由于电子表格包含机密信息,我宁愿使用 authorizations 私下进行查询。
我之所以要使用 Google 图表可视化功能(相对于服务器端电子表格应用程序)是因为查询大型数据集的速度。
我已尝试按照上述文档中的步骤操作。也就是说,创建一个客户端 ID,然后使用 gapi.auth 库对我自己进行身份验证,但我仍然收到错误消息。
当我添加授权库和文档中代码的第一部分时(使用 console.log 只是为了查看它到达的位置):
<script src="https://apis.google.com/js/auth.js?onload=init"></script>
<script>
var clientId = '1234.apps.googleusercontent.com';
var scopes = 'https://spreadsheets.google.com/feeds';
function init() {
console.log("here");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},handleAuthResult);
}
</script>
我收到以下错误:
1289869776-mae_html_user_bin_i18n_mae_html_user.js:41 dropping postMessage.. was from unexpected window
感谢任何指导。
我能否建议您从使用 Google sheets 改为使用带有 Google sheets 的 firebase 或仅使用 Firebase,然后再使用 Google后端的appscript。
我经常使用 Google 脚本使用来自 Google sheet 的数据更新 Firebase 时出现问题。然后我享受 Firebase 的速度和安全性,以提供超快速的用户体验。
有两个在 appscript 中使用 Firebase 的页面。例子page and the quick start。
此外,我放弃了使用 Google 自己的图表库,开始使用 high charts 或 chartJS,因为它们更易于访问。
由于您是使用 Google Apps Script 创建网络应用程序,因此没有必要 "authorize Google Charts to access private charts" 因为您可以使用 Google Apps Script 服务和方法从电子表格并将它们传递给 Google 图表。
在 Converting from UiApp + Chart Service to Html Service + Google Visualization API 上展示了如何将旧的仪表板示例从 UiApp + 图表服务转换为 HtmlService + Google 可视化 API。这说明了如何创建一个 Google Apps 脚本网络应用程序,该应用程序根据 Google 电子表格数据构建图表,而不 "requiring authorization" 因为它 "implicitly" 由 Google Apps 脚本处理。
从上面link
Two functions cooperate to retrieve the dashboard’s data and display it. As soon as the visualization API is loaded, the sendQuery() function is invoked. Using the google.script.run facility, it sends its request to the server-side getSpreadsheetData() function. This is an asynchronous operation, so two callbacks are provided, a successHandler and a failureHandler. One or the other will receive the result of the server call, depending on the outcome.
H/T 到 jfllmartin, author of an answer to Converting my google dashboard app from the UI service to the HTML service 上面 link 被分享。
相关
- Display Spreadsheet data in Sites with Html Service