1

I got a bit of a problem.

i created a googlesheet and included a script, like this, to send it as a pdf to my email address:

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Custom Menu')
  .addItem('Send summary', 'menuItem1')
  .addSeparator()      
  .addItem('Send summary&Week', 'menuItem2')
  .addToUi();
}

function menuItem1() {

var source   = SpreadsheetApp.getActiveSpreadsheet();
var subject  = source.getSheets()[9].getRange('G1').getValue(); //cell for              subject in sheet
var body     = source.getSheets()[9].getRange('F1').getValue(); 
var sheetNumSummary = 9; // first sheet(tab) is zero, second sheet is 1, etc..

var source = SpreadsheetApp.getActiveSpreadsheet();
var thema = source.getSheets()[9].getRange('f3').getValue();  // 
var mailTo = ('[email protected]'); //source.getSheets()        [0].getRange('D1').getValue(); // 'D1' cell which consists an emailaddress.
var name = source.getSheets()[9].getRange('G1').getValue(); // Name of              Attachement
var sheets = source.getSheets();
sheets.forEach(function (s, i) {
    if (i !== sheetNumSummary) s.hideSheet();
});
var url = Drive.Files.get(source.getId())
    .exportLinks['application/pdf'];
url = url + '&size=letter' + //paper size
    '&portrait=false' + //orientation, false for landscape
    '&fitw=true' + //fit to width, false for actual size
    '&sheetnames=false&printtitle=false&pagenumbers=false' + //hide optional
    '&gridlines=false' + //false = hide gridlines
    '&fzr=false'; //do not repeat row headers (frozen rows) on each page
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url, {
    headers: {
        'Authorization': 'Bearer ' + token
    }

now comes the weird thing. I'm able to use it with the Google sheet i used it with, but if i do a copy of it and use the script from the menue i get the message:

Access Not Configured. The API (Drive API) is not enabled for your project. Please use the Google Developers Console to update your configuration.

I checked everything in the admin and developer console, but couldn't find anything. I also activate:

Two-legged OAuth access control Allow access to all APIs The key and secret above are able to access any user's data for all Google Data APIs. Learn more

If i leave the copy of the 1st sheet and deactivate the API access, the 1st sheet (the origin) doesn't work anymore with the script and i get the above alert message. I have to delete the copy, reactivate the API access to make it work again. So, somehow i guess, the copy is working with the a script that only allows to work with one Project Sheet and not with the copy of that sheet. Is there somehow a way to make it work? Or, how can i add/attach the script to the copy. I used this script: function getSpreadsheetKey() { return SpreadsheetApp.getActiveSpreadsheet().getId(); };

and saw that it gives me the google key from the original sheet. that might be the reason why i cant use the script with the copy of the google sheet. But i still don't know how wire it correctly.

2 Answers 2

4

This message [(403) Access Not Configured] means that when you set up your Google Drive Access, you missed out "Activate the Drive API". You did not configure the Drive API to enabled in your Google account. To Activate the Drive API, go to Developers Console and Enable the Google Drive API.

Regarding 'Two -legged OAuth access control' it is not necessary to activate. As stated in the document: to bypass any access control checks in the Google Data API when using the domain key.

You have to Set up API access credentials [OAuth].

Here's a link to enable Drive API: https://developers.google.com/drive/v3/web/enable-sdk

For Two-legged OAuth access control document, here's the link: https://support.google.com/a/answer/162105?hl=en

1
  • 2
    Hey, found it. It was activated. What i didn't know was that i have to enable it for every single spreadsheet. Means following the link from > script editor > resources > advanced google services > Google Drive > and enable Api. Thought the Api switch is in general for the Google Drive and not selectiv. Thanks for the help. Jan 28, 2016 at 19:59
2

I just had this problem and it solved it self automatically.

It looks like there is some delay in allowing the API to being used (after it being enabled)

For reference I had enabled the API and setup the two stage OAuth.

Basically what happened was that I had a unit test to validate the access and:

  1. the test failed
  2. googled the error code
  3. saw this SO thread
  4. spent some time trying to figure out what was wrong
  5. run the test again (and it passed)
2
  • For reference, how long did it take to propagate, more or less? (1 minute, 1 hour, 1 day...?) Apr 27, 2019 at 16:57
  • It takes a few minutes. Aug 18, 2019 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.