授权Google图表访问私有电子表格 [英] Authorizing Google Charts to access private spreadsheets

查看:86
本文介绍了授权Google图表访问私有电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google Apps脚本创建一个Web应用程序,以使用 Google图表查询我的Google表格中的数据.

I am trying to create a Web App using Google Apps Script to query data from my Google Sheet using Google Charts.

当Google表格公开共享时,我已经能够成功查询电子表格,但是由于该电子表格包含机密信息,所以我宁愿使用

I have been able to successfully query the spreadsheet when the Google Sheet is publicly shared, however since the spreadsheet contains confidential info I would rather do it privately using authorizations.

之所以要使用Google Charts可视化功能(而不是服务器端Spreadsheet App),是因为查询大型数据集的速度很快.

The reason why I want to use Google Charts visualisation functions (as opposed to the server side Spreadsheet App) is because of the speed of querying large data sets.

我尝试按照上述文档中的步骤进行操作.也就是说,先创建一个客户端ID,然后使用gapi.auth库对自己进行身份验证,但我仍然会收到错误消息.

I have tried following the steps in the above documentation. That is, creating a client id then using the gapi.auth library to authenticate myself but I continue to receive an error.

当我从文档中添加授权库和代码的第一部分时(使用console.log只是为了了解它的最新进展):

When i add the authorization library and first part of the code from the documentation (with console.log simply to see where it get's up to):

<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删除postMessage ..来自意外窗口

1289869776-mae_html_user_bin_i18n_mae_html_user.js:41 dropping postMessage.. was from unexpected window

任何指导表示赞赏.

推荐答案

由于您正在使用Google Apps脚本创建网络应用,因此无需授权Google图表访问私有图表",因为您可以使用Google Apps脚本服务以及从电子表格中获取数据并将其传递给Google图表的方法.

Since you are creating your web app using Google Apps Script, it's not necessary to "authorize Google Charts to access private charts" because you could use Google Apps Script services and methods to get the data from the spreadsheets and pass them to Google Charts.

从UiApp + Chart Service转换为Html Service + Google Visualization API ,它说明了如何将旧的仪表板示例从UiApp + Chart Service转换为HtmlService + Google Visualization API.这说明了如何创建一个Google Apps Script网络应用程序,该应用程序可以从Google Spreadsheet数据构建图表,而无需由Google Apps Script隐式"处理,而无需需要授权".

On Converting from UiApp + Chart Service to Html Service + Google Visualization API it's shown how to convert the old dashboard example from from UiApp + Chart Service to HtmlService + Google Visualization API. This illustrates how to create a Google Apps Script web app that builds a chart from Google Spreadsheet data without "requiring authorization" as it's "implicitly" handled by Google Apps Script.

通过上面的链接

两个功能配合使用来检索仪表板的数据并显示它们.加载可视化API后,将立即调用sendQuery()函数.使用google.script.run工具,它将请求发送到服务器端的getSpreadsheetData()函数.这是一个异步操作,因此提供了两个回调:successHandler和failureHandler.一个或另一个将接收服务器调用的结果,具体取决于结果.

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 ,是将我的Google仪表板应用程序从UI服务转换为HTML服务,其中以上链接已共享.

H/T to jfllmartin, author of an answer to Converting my google dashboard app from the UI service to the HTML service where the above link was shared.

相关

这篇关于授权Google图表访问私有电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆