2

No matter what I do - my callback from newOpenLink() is not called. Code below is showing what I do: 1. I open link to a page on our server that gets some info 2. I use a string in "redirect_uri" part of the query string to reload page 3. page reloads (though instead of "https://script.google.com/macros/d/..." url it ends up with "https://script.google.com/a/macros/my_domain/d/…") - The text in a page:

Google Drive: Sorry, unable to open the file at this time. Please check the address and try again

Below is the code I am using - any help is much appreciated.

Thanks,

Sam

function getTokenCallback(data) {
    Logger.log("getTokenCallback executed");
}

public createInstance()
{
    var card = CardService.newCardBuilder();
    card.setHeader(
        CardService.newCardHeader()
            .setTitle('Login')
        );

    var section = CardService.newCardSection();

    var loginButton = CardService.newTextButton()
        .setText("Login")
        .setOpenLink(buildOpenLinkAction());

    section.addWidget(loginButton);
    card.addSection(section);
    return [card.build()];
}

public buildOpenLinkAction()
{
    var state = generateNewStateToken("getTokenCallback", "test");

    // baseUrl is global pointing to our external server
    var myUrl = baseUrl + "test-login.html";
    var htmlUrl = myUrl + "?redirect_uri=" + getRedirectURI() + "&state=" + state;

    return CardService.newOpenLink()
        .setUrl(htmlUrl)
        .setOpenAs(CardService.OpenAs.OVERLAY)
        .setOnClose(CardService.OnClose.RELOAD_ADD_ON);

}

public generateNewStateToken(callbackName, user_info) 
{
    return ScriptApp.newStateToken()
    .withMethod(callbackName)
    .withArgument("user_info", JSON.stringify(user_info))
    .withTimeout(3600)
    .createToken();
}

public getRedirectURI() 
{
    var scriptId = ScriptApp.getScriptId();
    return "https://script.google.com/macros/d/" + scriptId + "/usercallback";
}
Sam
  • 31
  • 3

3 Answers3

1

Finally figured it out - for whatever reason Google Apps Script is choking on trailing slash in front of query string - in my popup page I was calling script back like: https://script.google.com/macros/d/[script_id]/usercallback/?state=[state]

Calling without trailing slash in front of "?" works - https://script.google.com/macros/d/[script_id]/usercallback?state=[state]

This is very strange, since having trailing slash is considered good practice...

Sam
  • 31
  • 3
0

Might be worth reporting it here with google. This is one of those issues that will drive many devs crazy.

Michael Melo
  • 256
  • 1
  • 4
0

I found your bug report. I also found a bug where it doesn't properly parse URLs in text messages. You might want to mention RFC3986 in your bug report.

Which characters it breaks on apparently depends on what the Google teams have setup and where; testing your URLs and a similar URL, without even trying to break it like in my bug report, all links are broken in text messages when parsed!

enter image description here

Here's my bug report, for reference, for fun.

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
Jon8RFC
  • 85
  • 1
  • 8