Google电子表格从URL获取参数 [英] Google spreadsheet get parameters from URL
问题描述
我在插件菜单中点击登录,发送签名和回叫域名(当前片)。然后在服务中,我点击按钮,获取请求令牌,并将它返回给带有参数的指定域。
function onOpen(e )
{
Logger.log(SpreadsheetApp.getActiveSpreadsheet()。getUrl());
Logger.log(e.source.getUrl());
但是 .getUrl()$ c $根据
)与以下代码:
1)在步骤0,1,2之后,服务提供商应将我们重定向到Helper脚本(< (code> Web App
函数doGet(e)
{
var token = e.parameter.oauth_token,
code = e.parameter.oauth_verifier,
response; (令牌&& code&&& Root.setVerificationCode(token,code))
response =Success;
if
else
response ='错误';
返回HtmlService.createHtmlOutput(response);
$ b $ p
$ b 这里我们检索GET参数并将它们发送到Sheets web addon(根
)。
点击资源 - >库
并添加你的插件作为库。 根
只是一个标识符。
2)表单插件代码:
函数setVerificationCode(令牌,代码)
{
var oauth = new OAuth();
if(oauth.getAccessToken(code))
{
//在此处更改菜单
返回true;
}
else
返回false;
}
这些是实现OAuth 1.0所需的全部步骤。
PS现在我遇到了更改菜单的问题,但这是我的下一个问题。
I have an app, that links one service with Google Sheets by OAuth 1.0.
I click "login" in addon menu, send signature and callback domain (current sheet). Then in service I click on button, get request token and it returns me to the specified domain with parameters.
function onOpen(e)
{
Logger.log( SpreadsheetApp.getActiveSpreadsheet().getUrl() );
Logger.log( e.source.getUrl() );
}
But .getUrl()
doesn't contain them.
According to >this< I can't use doGet(e)
in Sheets and, because of OAuth, I can't use Web App, because I still need to pass these parameters to Sheets.
I tried to get it on client-side by window.top.location.href
, but had cross-domain errors.
Question: Can I get it? Or is it impossible?
解决方案 So, a partial answer to my question:
We need 2 different scripts. The first as Sheets web addon, the second as Web App. Next, we need to implement all the steps presented in the screenshot:
1) After steps 0, 1, 2 Service Provider should redirect us to Helper script (Web App
) with the following code:
function doGet(e)
{
var token = e.parameter.oauth_token,
code = e.parameter.oauth_verifier,
response;
if(token && code && Root.setVerificationCode(token, code))
response = "Success";
else
response = 'Error';
return HtmlService.createHtmlOutput(response);
}
Here we retrieving GET parameters and send them to Sheets web addon (Root
).
Click Resources -> Libraries
and add your addon as library. Root
is just an identifier.
2) Sheets addon code:
function setVerificationCode(token, code)
{
var oauth = new OAuth();
if(oauth.getAccessToken(code))
{
// change menu here
return true;
}
else
return false;
}
These are full steps you need to implement OAuth 1.0.
P.S. Now I have problems with changing menu, but it'll be my next question.
这篇关于Google电子表格从URL获取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!