首页 > 解决方案 > 将谷歌表格重定向到谷歌表格中的函数

问题描述

我正在尝试将URL重定向到google-sheets中的一个函数,该函数稍后应该做一些工作。

所以据我了解,我应该使用Deploy as wep app为这个函数创建一个API,然后使用这个 URL。

所以我所做的是创建 2 个Api.gs包含此代码的脚本文件

function test() {
  Logger.log('Success!!')
}

这应该是我将为它创建一个 api 的那个。

另一个文件Authentication.gs包含此代码功能

showSideBar() {
    var authorizationUrl = 'https://www.upwork.com/ab/account-security/oauth2/authorize?redirect_uri=The_Api_URL_generated_for_the_function_above&client_id=clientID&response_type=token';
    var template = HtmlService.createTemplate(
        '<a href="<?= authorizationUrl ?>" target="_blank">Press here to authroze</a>.');
    template.authorizationUrl = authorizationUrl;
    var page = template.evaluate().setTitle('Authroize');
    SpreadsheetApp.getUi().showSidebar(page); 
}

这显示了一个侧边栏,当我按下链接时,它会正确重定向我但出现错误,Missing or invalid redirect_uri parameter value.

我正在尝试验证 upwork 并将其再次重定向到 google-sheets

所以我想知道我做错了什么?或者如果我正在做甚至可能?

标签: google-apps-scriptgoogle-sheetsspreadsheetupwork-api

解决方案


尝试这个:

将其输入脚本编辑器并运行 showmysidebar() 然后单击按钮并看到 toast 出现在右下角。

function test() {
  SpreadsheetApp.getActive().toast("Success");
}

function showmysidebar() {
  var html='<input type="button" value="test" onclick="google.script.run.test();" />';
  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutput(html));
}

推荐阅读