简体   繁体   中英

Discord send Oauth2 redirect url with the 'code' in url-query. How to get that code in my google script

We can't get the url query 'code' to our google script.

1

This discord documentation https://discordapp.com/developers/docs/topics/oauth2 shows that we get an redirect url with a query names 'code' back.

Like: https://nicememe.website/?code=NhhvTDYsFcdgNLnnLijcl7Ku7bEEeee

2

we get this url (my version) and now we want to call with that redirect a google app script. Something like: https://script.google.com/macros/s/AKfycbyyt9-FiVv0zXOr8p8pMfojwEs2AXvBftVN1xdWeU3UQ1xgURD/exec ? code=NhhvTDYsFcdgNLnnLijcl7Ku7bEEeeD

3

How we want to handle this 'code=NhhvTDYsFcdgNLnnLijcl7Ku7bEEeeD' in the app script.

We already tried: release that script as an app. so we get the redirect url. its the part at the url that redirect us to the google script.

But if we do this, we have a problem: if we release the script as an app, we have to call the function doGet(e){}

In the script an we have to return something.

function doGet(e) {
    code = ScriptApp.getService().getUrl();
    Logger.log(code);
    return ContentService.createTextOutput(code);
}

at the logger in google script I only get this url.

https://script.google.com/macros/s/AKfycbyyt9-FiVv0zXOr8p8pMfojwEs2AXvBftVN1xdWeU3UQ1xgUDD/exec

But if we break the program with some error, I get the right url in the url bar at the top. So why we get the right redirect url, but some little seps later we only have the normal url (without code) left?

and how i can use console.log? Normally in js i can open google DevTools an get the console log. but at google script that doesn't work :(

Thanks for any help <3

Got it!

function doGet(e){

  var codeStr = e.queryString;
  var codeArray = codeStr.split("=");
  var code = codeArray[1];
  Logger.log(code);

  return ContentService.createTextOutput(code);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM