【发布时间】:2014-02-02 01:44:01
【问题描述】:
我试图让我的应用程序脚本 webapp 以“用户访问 webapp”的身份执行,但它的 bigquery 应该以我(开发人员)的身份运行。 (如果我像我一样运行 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>
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>
我生成了一个客户端 ID 作为浏览器应用程序,https://script.google.com 作为服务器地址。使用上面的代码,我收到此错误:无法读取未定义的属性“authorize_m___”。
我的问题是双重的:1)应用程序脚本 webapp 的身份验证方式是否与 javascript 应用程序的身份验证方式相同? IE。我可以使用该代码作为我的应用程序脚本的指南吗?
还有 2) 关于如何调试 javascript 示例代码的任何建议?请注意,我将此代码作为应用程序脚本 webapp 运行......这可能是一个错误......
【问题讨论】:
-
继续传奇:看起来授权必须通过服务器,即使使用应用程序脚本:
If your application is a publicly accessible online dashboard, you'll need to securely proxy the requests through a server-side application, such as a Google App Engine application. BigQuery queries must be charged to a specific project, so the Google App Engine app should keep track of the requests being made to ensure they represent legitimate usage of your application.这看起来很奇怪,因为交易功能可以完全隐藏,所以秘密可能秘密通过。
标签: authentication google-apps-script google-bigquery