0

In a script connected to a spreadsheet, I loop through the rows of the spreadsheet and add coursework via a call to Classroom.Courses.CourseWork.create(ClassSource, courseId)

I had tested quite a bit and today was trying to weekly assignments for the year to a course I had created. I got an error on the 10th add. I assumed that it was a problem with a timeout so I added a sleep statement. Nothing worked so I tried starting with a new script.

If I just put in the code to access the spreadsheet,

    var sheet = SpreadsheetApp.getActiveSheet();
    var rangeSS = sheet.getDataRange()
    var data  = sheet.getDataRange().getValues();

no problem with authorization but then the call to Classroom doesn't work.

So then I add in

"oauthScopes":  [
  "https://www.googleapis.com/auth/classroom.coursework.students.readonly",
  "https://www.googleapis.com/auth/classroom.courses.readonly"
],

under View -> Show Manifest File

Strangely, at this point, I get the error:

You do not have permission to call getActiveSheet.

I have Sheets enabled via Resources -> Advanced Google Services. I've enabled Classroom and Sheets via Scripts Dashboard I've tried this several times on both Opera and Chrome, sometimes also enabling Google Drive.

Nothing seems to work. Wondering if anyone else has seen this problem.

function myFunction() {
  var weekday = new Array("Sunday", "Monday","Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
  var sheet = SpreadsheetApp.getActiveSheet();
  var rangeSS = sheet.getDataRange()
  var data  = sheet.getDataRange().getValues();

  for (var i = 1; i < data.length; i++) {
    // set up ClassSource from data in the spreadsheet row
    Classroom.Courses.CourseWork.create(ClassSource, courseId)
  ...
tehhowch
  • 9,645
  • 4
  • 24
  • 42
  • 1
    If you explicitly define `oauthScopes` in your manifest file, those are the scopes that are used. No automatic scopes are added - otherwise you would not be able to reduce to the minimum scopes necessary, since Apps Script's auto-scoping would add the most permissive scopes possible. – tehhowch Jul 10 '18 at 17:22
  • Note that the Sheets advanced service merely *enables* the client library for the Sheets REST API - which is not the same as the Spreadsheet Service accessed with `SpreadsheetApp`. It does not provide or grant any oauth scopes. – tehhowch Jul 10 '18 at 17:24
  • Related (not quite a duplicate): https://stackoverflow.com/questions/46923442/permissions-error-using-urlfetchapp-in-gmail-add-on – tehhowch Jul 10 '18 at 17:32
  • 1
    Change the appsscript.json file back to the original state, then save it. The click the File menu, and the Project properties menu item. Click on the Scopes tab. copy the scopes. Add those scopes to the manifest file along with the other scopes that you want to use, and save the manifest file. – Alan Wells Jul 10 '18 at 23:48
  • Thanks for the help. I changed the manifest file as you suggested and now the script runs. I'm back to getting the "Internal Error encountered. (line 147, file Code) . Line 147 is the call to . Classroom.Courses.CourseWork.create(ClassSource, courseId) – Tom Keeler Jul 11 '18 at 13:28
  • Everything running. Just had a wrap-around error when I added days and the month changed. – Tom Keeler Jul 11 '18 at 16:13
  • Thanks so much. This script will save me hundreds of hours of work and I was really stuck. – Tom Keeler Jul 11 '18 at 16:14

0 Answers0