title: Setting Oauth2 to get access token using spreadsheets
body: <p>I've been using <strong>Spreadsheets</strong> and <strong>upwork</strong>, as I want to integrate between them.</p>
  <p>So I'm trying to make authorization for upwork through spreadsheets, using the <a href="https://github.com/gsuitedevs/apps-script-oauth2" rel="nofollow noreferrer">documentation steps</a> and everything is going fine. But when i authorize my account i see that the <strong>response_type</strong> is not a <code>token</code>, it's a <code>code</code>.</p>
  <pre><code> function authorize() {
   return OAuth2.createService('upwork')
  
        // Set the endpoint URLs, which are the same for all Google services.
        .setAuthorizationBaseUrl('https://www.upwork.com/ab/account-security/oauth2/authorize')
        .setTokenUrl('https://www.upwork.com/ab/account-security/oauth2/token')
  
        // Set the client ID and secret, from the Google Developers Console.
        .setClientId('cleintID')
        .setClientSecret('clientSecret')
        .setRedirectUri('https://script.google.com/macros/d/{Script-ID}/usercallback') 
   
        .setTokenFormat(OAuth2.TOKEN_FORMAT.FORM_URL_ENCODED)
        
        // Set the name of the callback function in the script referenced
        // above that should be invoked to complete the OAuth flow.
        .setCallbackFunction('authCallback')
  
        // Set the property store where authorized tokens should be persisted.
        .setPropertyStore(PropertiesService.getUserProperties())
  }
  </code></pre>
  <blockquote>
  <p>So this is my first question, Is there is a way to set the response_type to <code>token</code>, as i am setting in the picture above the clientID,redirectUri... (I tried <code>setResponseType</code> but it doesn't exist)</p>
  </blockquote>
  <p>although working as it's and using <code>response_type=code</code>, after authorization the a request should be returned to  the</p>
  <pre><code>function as below function authCallback(request) {
    var driveService = authorize();
    Logger.log(request) //this is always null
    var isAuthorized = driveService.handleCallback(request);
    if (isAuthorized) {
      Logger.log('Yaaay')
      return HtmlService.createHtmlOutput('Success! You can close this tab.');
    } else {
      Logger.log('Naaay')
      return HtmlService.createHtmlOutput('Denied. You can close this tab');
    }
  }
  </code></pre>
  <blockquote>
  <p><code>authorize()</code> is not called ??</p>
  </blockquote>
  <p>Finally below is the whole code i'm using.</p>
  <pre><code>function authorize() {
   return OAuth2.createService('upwork')
  
        // Set the endpoint URLs, which are the same for all Google services.
        .setAuthorizationBaseUrl('https://www.upwork.com/ab/account-security/oauth2/authorize')
        .setTokenUrl('https://www.upwork.com/ab/account-security/oauth2/token')
  
        // Set the client ID and secret, from the Google Developers Console.
        .setClientId('cleintID')
        .setClientSecret('clientSecret')
        .setRedirectUri('https://script.google.com/macros/d/{Script-ID}/usercallback') 
   
        .setTokenFormat(OAuth2.TOKEN_FORMAT.FORM_URL_ENCODED)
        
        // Set the name of the callback function in the script referenced
        // above that should be invoked to complete the OAuth flow.
        .setCallbackFunction('authCallback')
  
        // Set the property store where authorized tokens should be persisted.
        .setPropertyStore(PropertiesService.getUserProperties())
  }
  
  function redirect() {
    var driveService = authorize();
    if (!driveService.hasAccess()) {
      var authorizationUrl = driveService.getAuthorizationUrl();
      var template = HtmlService.createTemplate(
          '&lt;a href=&quot;&lt;?= authorizationUrl ?&gt;&quot; target=&quot;_blank&quot;&gt;Press here to authroze&lt;/a&gt;.');
      template.authorizationUrl = authorizationUrl;
      var page = template.evaluate().setTitle('Authroize');
      SpreadsheetApp.getUi().showSidebar(page);
    }
  }
  
  function authCallback(request) {
    var driveService = authorize();
    Logger.log(request)
    var isAuthorized = driveService.handleCallback(request);
    if (isAuthorized) {
      Logger.log('Yaaay')
      return HtmlService.createHtmlOutput('Success! You can close this tab.');
    } else {
      Logger.log('Naaay')
      return HtmlService.createHtmlOutput('Denied. You can close this tab');
    }
  }
  </code></pre>
  <blockquote>
  <p><strong>Update</strong>: I found that redirectURI is incorrect format, as google require the URI to be in the form of <code>https://script.google.com/macros/d/{SCRIPT ID}/usercallback</code>, so now the error changes and i got a failure</p>
  </blockquote>
  <pre><code>    Error: Error retrieving token: 404: {&quot;&lt;!DOCTYPE html&gt;\n&lt;html lang&quot;:&quot;\&quot;en\&quot;&gt;\n&lt;head&gt;\n\n &lt;meta name&quot;,&quot;&quot;:&quot;undefined&quot;,&quot; window.performance.mark 
  
  &quot;:&quot;undefined&quot;,&quot; window.performance.mark(name);\n }\n\n function remove_mark(name) {\n window.performance &quot;:&quot;undefined&quot;,&quot; window.performance.clearMarks &quot;:&quot;undefined&quot;,&quot; window.performance.clearMarks(name);\n }\n\n function 
  
  create_measure(name, startMark, endMark) {\n window.performance &quot;:&quot;undefined&quot;,&quot; window.performance.measure &quot;:&quot;undefined&quot;,&quot; window.performance.measure(name, startMark, endMark);\n }\n\n function remove_measure(name) {\n window.performance &quot;:&quot;undefined&quot;,&quot; window.performance.clearMeasures &quot;:&quot;undefined&quot;,&quot; window.performance.clearMeasures(name);\n }\n&lt;/script&gt;\n &lt;link 
  
  rel&quot;:&quot;\&quot;stylesheet\&quot; href&quot;,&quot;amp;site.application&quot;:&quot;AccountSecurity&quot;,&quot;amp;site.version&quot;:&quot;ed46c62af44692608c290dd0b498fa933b20c567&quot;,&quot;amp;site.environment&quot;:&quot;prod&quot;,&quot;amp;server-error.status&quot;:&quot;1&quot;,
  
  &quot;amp;server-error.label&quot;:&quot;404+-+Agate&quot;,&quot;amp;server-error.traceId&quot;:&quot;5c7d08790a6473b1-IAD\&quot; height&quot;,&quot;l&quot;:&quot;'+l:'';j.async&quot;,&quot;granted_time&quot;:1598271686} (line 541, file &quot;Service&quot;)
  </code></pre>