Error: Access not granted or expired. Service_.getAccess

505 views
Skip to first unread message

Nibesh Khadka

unread,
Dec 22, 2022, 4:49:15 AM12/22/22
to Google Apps Script Community
I get this error,
 Error: Access not granted or expired.
Service_.getAccessToken
@ Service.gs:518

I tried clearing and reassigning permission but it does not work. I am using GAS Oauth2 library as well. It suddenly happened a few days ago.
I cannot work further due to this. I would appreciate the help.
Message has been deleted

Nibesh Khadka

unread,
Dec 25, 2022, 4:00:36 AM12/25/22
to Google Apps Script Community
Hi, guys thanks for trying. I actually found the solution to the problem.
The code 
OAuth2.createService('SERVICE_NAME');

From OAuth2 Library, where the "SERVICE_NAME" is the ScriptUserPropertry, which is saved to the script, had expired. So, I reset it and everything is working fine now.

Juan Carlos “WebMaster” Ajahuana

unread,
Mar 20, 2023, 10:21:25 PM3/20/23
to Google Apps Script Community
function run() {
  var service = getDriveService_();
  if (service.hasAccess()) {
    var response = UrlFetchApp.fetch(url, {
      headers: {
        Authorization'Bearer ' + service.getAccessToken()
      }
    });
    var result = JSON.parse(response.getContentText());
    Logger.log(JSON.stringify(resultnull2));
  } else {
    var authorizationUrl = service.getAuthorizationUrl();
    Logger.log('Open the following URL and re-run the script: %s',
        authorizationUrl);
  }
}

fix solution to getAccessToken :)
Reply all
Reply to author
Forward
0 new messages