I am using the Google API Client Libraries PHP (Beta) and I have been successful at getting authorization for both the Calendar and Task api.
I have also created calendars, inserted events and updated events.
The next step was to create Tasks lists. However, I keep getting error:
Fatal error: Class 'Task' not found for $task = new Task(); when I run the sample code:
require_once 'vendor/autoload.php'; //this worked for all the calendar functions
$client = new Google_Client();
$client_id="xxxxOmitted";
$client_secret="xxxxxxxOmitted";
$redirect_uri='xxxxOmitted';
$client->setApplicationName("XXXXOmitted");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setAccessToken($_SESSION['token']);
$service = new Google_Service_Tasks($client);
$task = new Task();
$task->setTitle('New Task');
$task->setNotes('Please complete me');
$task->setDue(new TaskDateTime('2010-10-15T12:00:00.000Z'));
$result = $service->insertTasks('@default', $task);
echo $result->getId();
Found work around for tasks but not for inserting tasklist
$service = new Google_Service_Tasks($client);
$task= new Google_Service_Tasks_Task();
$task->setTitle('New Task');
$task->setNotes('Please complete me');
$result = $service->tasks->insert('@default', $task);
echo $result->getId();
Can someone help with insert tasklists? Thanks in advance!
Similar question:Only list method is working in Google task api PHP
Similarly to what done for Tasks, see the following code for Tasklists.
A new service for Google_Tasks is instantiated. A new tasklist is created, with title set and then inserted.