0

I have looked at the answer here: How do I stop the error, Authorisation is required to perform that action in Google Script . This doesn't not solve my problem because I didn't change any of my code and I already have authorized the code the first time I ran it. All of a sudden I get the Authorization is required to perform that action error.

I have also tried this link https://developers.google.com/apps-script/troubleshooting#common_errors and ran a blank function in the editor function test() { var a=1}. This runs ok without giving me a prompt to authorize the script and with no errors. So after following Google's instructions: To authorize the script, open the Script Editor and run any function. I'm still getting the Authorization is required to perform that action error.

I'm not doing anything fancy. The script has only one .gs file, and the file only has one function. I'm not using any advanced services and I'm not linking it to any libraries.

Update: I've tried to make a copy of the file, and I then go into script editor again to run the code. This time the authorization pop is there, so I click on continue. The follow shows up: the code would like to

View and manage the files in your Google Drive. Send email as you Connect to an external service

I click on "Accept". The code starts to run, 2 seconds later Authorization is required to perform that action. Now every time I try running the code, it doesn't even give me the authorization pop up. It just gives me the error.

here is the oauth part of the code. The rest of the code is just a few more lines more.

  var oauthConfig = UrlFetchApp.addOAuthService("google");
  var scope = "https://docs.google.com/feeds/";

  //make OAuth connection
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oauthConfig.setConsumerKey("anonymous");
  oauthConfig.setConsumerSecret("anonymous");

  //get request
  var request = {
    "method": "GET",
    "oAuthServiceName": "google",
    "oAuthUseToken": "always",
    "muteHttpExceptions": true
  };
Community
  • 1
  • 1
jason
  • 3,811
  • 18
  • 92
  • 147

1 Answers1

1

oauthConfig in UrlFetchApp has been deprecated. It was turned off on June 26th. The following link will show you how to migrate your code from oauthConfig to the Oauth1 library.
https://developers.google.com/apps-script/migration/oauth-config

EDIT: From the comments it looks like you want to save a spreadsheet as a pdf in drive. here is a snippet of code that can do that.

  var ss = SpreadsheetApp.openById(fileId);
  var blob = ss.getBlob().setName("new_file_name.pdf");
  DriveApp.createFile(blob);
Ben Kane
  • 9,331
  • 6
  • 36
  • 58
Spencer Easton
  • 5,642
  • 1
  • 16
  • 25
  • it seems like that's the error. But from your link it seems Oauth1 is also being turned off. The link https://github.com/googlesamples/apps-script-oauth2 is giving me some trouble. All i'm trying to do is this http://stackoverflow.com/questions/12881547/exporting-spreadsheet-to-pdf-then-saving-the-file-in-google-drive but the `Docslist` no longer works. – jason Jun 02 '15 at 02:24
  • added a bit of code to show how to convert a spreadsheet to a pdf and save it to drive. – Spencer Easton Jun 02 '15 at 12:21
  • thanks Spencer. I'm more looking for the oauth2 part. other code I had from before. if you want to try this question, be my guest. http://stackoverflow.com/questions/30586559/printing-spreadsheet-to-pdf-then-saving-file-in-drive-using-oauth2 . I realize it's the migration to oauth2 code that is difficult for me – jason Jun 02 '15 at 12:54