Apps脚本webapp:如何验证bigquery? [英] Apps Script webapp: how to authenticate bigquery?

查看:136
本文介绍了Apps脚本webapp:如何验证bigquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的应用程序脚本webapp作为用户访问web应用程序来执行,但它的大量查询应该以我作为开发者的身份运行。 (如果我以我的身份运行webapp,一切正常......)我查看了 https: //developers.google.com/bigquery/docs/authorization 。没有应用程序脚本示例,所以我试图让JavaScript示例工作。

 < html> 
< head>
< script src =https://apis.google.com/js/client.js>< / script>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js>< / script>
< script>

函数auth(){
gapi.auth.authorize(config,function(){
gapi.client.load('bigquery','v2');
$('#client_initiated')。html('BigQuery client authorized');
$('#auth_button')。fadeOut();
$('#dataset_button')。fadeIn() ;
});
}

//用户提交的变量
var projectNumber ='XXXXXXXXXX';
var clientId ='XXXXXXXXXX.apps.googleusercontent.com';

var config = {
'client_id':clientId,
'scope':'https://www.googleapis.com/auth/bigquery'
} ;

函数listDatasets(){
var request = gapi.client.bigquery.datasets.list({
'projectId':projectNumber
});
request.execute(function(response){
$('#result_box')。html(JSON.stringify(response.result.datasets,null));
});
}
< / script>
< / head>
< body>
< button id =auth_buttononclick =auth();>授权< /按钮>
< div id =client_initiated>< / div>
< button id =dataset_buttonstyle =display:none; onclick =listDatasets();>显示数据集< /按钮>
< div id =result_box>< / div>
< / body>
< / html>

我使用 https://script.google.com 作为服务器地址。通过上面的代码,我得到这个错误:无法读取未定义的属性'authorize_m___'。

我的问题有两个:1)应用程序脚本webapp会以与JavaScript应用程序验证相同的方式验证身份吗?即我可以使用该代码作为我的应用程序脚本的指南吗?

以及2)关于如何调试javascript示例代码的任何建议?请注意,我将此代码作为应用程序脚本webapp运行....这可能是一个错误....

解决方案

答案...或解决方法的答案在这里给出:如何将参数从一个Google-Apps-Script传递到另一个并执行?



我可以使用两阶段身份验证代替直接身份验证:用户以他/她自己的身份登录,获取用户的名称以查找他们的文件,然后切换到使用BigQuery和高管作为开发人员的Web应用程序。



适用于应用程序脚本下高级服务身份验证的一种很好的解决方法....


I am trying to get my apps script webapp to execute as "user accessing the webapp", but its bigquery should run as me, the developer. (If I run the webapp as me, everything works...) I looked at the documentation at https://developers.google.com/bigquery/docs/authorization. There is no apps script example, so I tried to get the javascript example working.

<html>
<head>
<script src="https://apis.google.com/js/client.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>

  function auth() {
    gapi.auth.authorize(config, function() {
        gapi.client.load('bigquery', 'v2');
        $('#client_initiated').html('BigQuery client authorized');
        $('#auth_button').fadeOut();
        $('#dataset_button').fadeIn();
    });
  }

  // User Submitted Variables
  var projectNumber = 'XXXXXXXXXX';
  var clientId = 'XXXXXXXXXX.apps.googleusercontent.com';

  var config = {
    'client_id': clientId,
    'scope': 'https://www.googleapis.com/auth/bigquery'
  };

  function listDatasets() {
    var request = gapi.client.bigquery.datasets.list({
      'projectId':projectNumber
    });
    request.execute(function(response) {
        $('#result_box').html(JSON.stringify(response.result.datasets, null));
    });
  }
</script>
</head>
<body>
<button id="auth_button" onclick="auth();">Authorize</button>
<div id="client_initiated"></div>
<button id="dataset_button" style="display:none;" onclick="listDatasets();">Show datasets</button>
<div id="result_box"></div>
</body>
</html>

I generated a client id as a browser app with https://script.google.com as the server address. With the code above, I get this error: Cannot read property 'authorize_m___' of undefined.

My question is twofold: 1) Would an apps script webapp authenticate in the same way as the javascript app authenticates? I.e. can I use that code as a guide for my apps script?

And 2) any suggestions about how to debug the javascript sample code? Note that I ran this code as an apps script webapp.... That is probably an error....

解决方案

The answer... or workaround answer is given here: How to pass parameters from one Google-Apps-Script to another and execute?

I can use two stage authentication in place of direct authentication: the user logs in as him/herself, I get the user's name to find their files, then switch to a webapp that uses BigQuery and execs as me, the developer.

A good workaround for advanced services authentication under apps scripts....

这篇关于Apps脚本webapp:如何验证bigquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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