Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

deployment - New Google App Script IDE changed how GetUrl() works

I have been using ScriptApp.getService().getUrl() server side to return the current dev or prod (exec) url to the client side. I do this so that I can provide a "permalink" or copy URL function so that users can link to a specific record in the app. Something like:

https://script.google.com/macros/s/{ID}/exec?recordId=999

Recently, when Google rolled out the new IDE, I started having a problem where ScriptApp.getService().getUrl() returns only the Legacy URL.

I was able to recreate this with a new project, so maybe this is a new IDE bug?

Steps to Recreate

  1. Create a new App Script Project.
  2. Make sure you select "Use Legacy Editor"
  3. Create an app that displays the URL

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  </head>
  <body>
    <h2>Hello World 2</h2>
    <div id='test'>xx</div>
      <script>
      $(document).ready(function() {
          google.script.run.withSuccessHandler(success).getUrl();
      });

      function success(url) {
          $("#test").html(url);
      }
  </script>
  </body>
</html>

Code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index');
}

function getUrl(){
  Logger.log(ScriptApp.getService().getUrl());
  return ScriptApp.getService().getUrl();
}
  1. Menu Publish -> Deploy as Web App (old IDE).
  2. Open the new deployed app, and confirm that the URL on screen is the same as the URL you're hitting.
  3. Menu Publish -> Deploy as Web App, click "Latest Code" link to get to dev.
  4. Verify it shows the correct dev URL.
  5. Click "Use new Editor" button to switch to new IDE.
  6. Click Deploy -> New Deployment.
  7. Enter a description and click "Deploy"
  8. Now open the new URL that is published.
  9. Note how the URL in the address bar and the URL on the page from the getURL call are different: on Page is the same as the old IDE URL.

So the question is: How do I get Google to completely archive the old URL?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(my response from issue tracker, here for reference https://issuetracker.google.com/issues/170799249#comment26)

In legacy editor user had to save new project version and then publish it (or do it at once) There were two links: dev (head) and published version with static link (web app meta-version)

In a new editor, every time project is deployed it gets a new ID and new link but web app meta-version is not updated. There is no way to control this published with the static link version (web app meta-version). So bookmarks and reverences point to the old version or are broken if this version was archived. This is BAD!

ScriptApp.getService().getUrl() seems to always return the same static link to web app meta-version. This what is confusing OP IMHO.

Workaround that worked for me: switch to legacy editor, publish (deploy as web app) the latest (or required) version. It will became web app meta-version reachable by the same old link. I assume the same returned by ScriptApp.getService().getUrl(). Not sure about dev link.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...