1

I'm not able to create tasks from script. Neither of the below are working.

var newlist = Tasks.newTaskList().setTitle("This tasklist is created from script");

var newTask = Tasks.newTask().setTitle("This task has been created from script");

I'm new to Google apps script. What am I doing wrong? I've also added the OAuthApp library. But I'm always getting

ReferenceError: "Tasks" is not defined.

Can someone tell me what I'm doing wrong?

Dawn
  • 13
  • 3
  • Did you enable the Tasks API? https://developers.google.com/apps-script/service_tasks – Fred Jan 28 '13 at 14:20
  • Thank you, I got it. Although I'm still struggling to figure out where to use the key – Dawn Jan 29 '13 at 15:55

1 Answers1

3
  1. You should create a project with the Tasks API enabled here - https://code.google.com/apis/console/
  2. Copy the key, and then in the Script Editor, in the menu go Resources -> Use Google APIs and paste in the key

enter image description here

Arun Nagarajan
  • 5,547
  • 1
  • 22
  • 19
  • Yes, I did paste the key where indicated; but I'm still not able to create a new list, nor new task. What am I doing wrong? Do I have to send the key as parameter somewhere? – Dawn Jan 30 '13 at 12:00
  • Are you getting the same error message you mention above? Can you confirm that you only pasted the key where in the screen shot above says "YOUR_KEY_HERE" and no where else? – Arun Nagarajan Jan 30 '13 at 13:17
  • No, that error was fixed when the API was turned on. But the new task or new list does not appear in my tasks. – Dawn Jan 30 '13 at 14:55
  • Do I have to add any code for saving it? Documents, Spreadsheets, Contacts & Events also don't need any extra code for saving after being created, so I assumed Tasks wouldn't either. But do I? – Dawn Jan 31 '13 at 09:25
  • Infact `newlist.getTitle();` is returning the title but `newlist.getSelfLink();` is returning null Is there a problem somewhere? or am I doing something wrong? – Dawn Jan 31 '13 at 09:43
  • Its working. I missed this line `Tasks.Tasklists.insert(newList);` Sorry for the mess on this thread. Thanks a lot – Dawn Jan 31 '13 at 10:17
  • Ok glad to know. Please close out this question with that comment when you get a chance. – Arun Nagarajan Jan 31 '13 at 15:13