Google Tasks API Error when Creating New Task - Fatal error: Class 'Task' not found

337 views Asked by At

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

1

There are 1 answers

0
GabrieleMartini On

Similarly to what done for Tasks, see the following code for Tasklists.

$service = new Google_Service_Tasks($client);
$tasklist= new Google_Service_Tasks_TaskList();
$tasklist->setTitle('New TaskList');
$service->tasklists->insert($tasklist);

A new service for Google_Tasks is instantiated. A new tasklist is created, with title set and then inserted.