I run Google script applications with my C # application approximately every 1.5 minutes. Script applications move content between spreadsheets and edit worksheets. I also use Drive API.
My script works fine for a long time, except that I get authorization errors for 5 minutes every hour.
Here is my code that handles authorization:
class Authentication { public static ScriptService ScriptsAuthenticateOauth(UserCredential credential) { try { ScriptService service = new ScriptService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "MyApp", }); return service; } catch (Exception ex) { Console.WriteLine(DateTime.Now.ToString("HH:mm") + ": An authentication error occurred: " + ex.InnerException); return null; } } public static UserCredential getCredential(string clientId, string clientSecret, string userName) { string[] scopes = new string[] { DriveService.Scope.Drive,
I get the following services:
var credential = Authentication.getCredential(CLIENT_ID, CLIENT_SECRET, Environment.UserName); DriveService driveService = Authentication.DriveAuthenticateOauth(credential); ScriptService scriptService = Authentication.ScriptsAuthenticateOauth(credential);
But at about the end of the hour, the script application causes the following error:
Script error message: Authorization is required to perform that action.
Just to be clear, it works at all other times, but not in those 5 minutes at the end of the hour. I activated the Google Drive APIs both on my developer console and in the Resources> Advanced Google Services ... section of the script editor application.
So what's going on? Could this be fixed?
source share