function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JhanawaJhanawa 

RefreshToken Timeout - oAuth2 - apps script - HELP!

Hi,
My script was running for about a week, I changed the triggers to run less frequently (1x day) so the session was expired.
I added the RefreshToken to it and it's not working and I'm not sure why.
My connected app has the following Scopes:
Access your basic information (id, profile, email, address, phone)
Access and manage your data (api)
Provide access to your data via the Web (web)
Perform requests on your behalf at any time (refresh_token, offline_access)

The app authenticates no problem when I run it manually and connect, so I know the connected App works.

When I view the refreshToken in the log, I can see it, so I know it is stored.

function refreshToken() {
  var props = PropertiesService.getUserProperties();
  var uProps = JSON.parse(props.getProperties()['oauth2.salesforce']);  // assumes the service's name is "salesforce" (set when service was created)
  Logger.log(uProps.refresh_token);
  var sProps = PropertiesService.getScriptProperties();
  var clientId = sProps.getProperty('sfConsumerKey');
  var clientSecret = sProps.getProperty('sfConsumerSecret');
   var response = UrlFetchApp.fetch('login.salesforce.com/services/oauth2/token?grant_type=refresh_token&client_id=' + clientId + '&client_secret=' + clientSecret + '&refresh_token=' + uProps.refresh_token, {method: 'POST'});
  var nuProps = JSON.parse(response);
  uProps.signature = nuProps.signature;
  uProps.access_token = nuProps.access_token;
  uProps.issued_at = nuProps.issued_at;
  props.setProperty('oauth2.salesforce', JSON.stringify(uProps));
  //Logger.log(nuProps);
}