title: Trouble authorizing using OAuth with StackExchange API and Apps Script
body: <p>I'm trying to access StackExchange API, using OAuth in Google Apps Script. I'm using <a href="https://github.com/gsuitedevs/apps-script-oauth2" rel="nofollow noreferrer">this library</a>.</p>
  
  <p>When I call the below, I don't have access at first (which is expected). The authorization URL I log is:</p>
  
  <pre><code>https://stackoverflow.com/oauth?client_id=14205&amp;response_type=code&amp;redirect_uri={URI}&amp;state={STATE}&amp;scope=read_inbox 
  </code></pre>
  
  <p>Pasting the autorizationURL into my browser, I get the page that reads:</p>
  
  <pre><code>"Error: Token response not valid JSON: SyntaxError: Unexpected token: a (line 532, file "Service", project "OAuth2")"
  </code></pre>
  
  <p>What I run from Apps Script:</p>
  
  <pre><code>function getMentions() {
     var service = getStackExchangeService_();
     Logger.log(service.hasAccess());
     if (service.hasAccess()) {
  
       //get token and call API
     }
     else {
     Logger.log("App has no access yet.");
  
     // open this url to gain authorization from Stack Exchange
     var authorizationUrl = service.getAuthorizationUrl();
  
     Logger.log("Open the following URL and re-run the script: %s",
       authorizationUrl);
     }
   }
  </code></pre>
  
  <p>My Oauth.gs page:</p>
  
  <pre><code>function getStackExchangeService_() {
    var CLIENT_ID = PropertiesService.getScriptProperties().getProperty('SE_CLIENT_ID');
    var CLIENT_SECRET = PropertiesService.getScriptProperties().getProperty('SE_CLIENT_SECRET');
  
    return OAuth2.createService('StackExchange')
    .setAuthorizationBaseUrl('https://stackoverflow.com/oauth')
    .setTokenUrl('https://stackoverflow.com/oauth/access_token')
    .setClientId(CLIENT_ID)
    .setClientSecret(CLIENT_SECRET)
    .setCallbackFunction('authCallbackSE')
    .setPropertyStore(PropertiesService.getUserProperties())
    .setRedirectUri('https://script.google.com/macros/d/{SCRIPT ID}/usercallback')
    .setScope('read_inbox');
  }
  
  function authCallbackSE(request) {
    var SEService = getStackExchangeService_();
    var isAuthorized = SEService.handleCallback(request);
    if (isAuthorized) {
      return HtmlService.createHtmlOutput('Success! You can close this tab.');
    } else {
      return HtmlService.createHtmlOutput('Denied. You can close this tab');
    }
  }
  </code></pre>
  
  <p>Unclear where I am going wrong, but I assume that I should be redirected to an authorization page when I put in the authorizationURL. Thanks!</p>