0

I am trying to insert a new task into TaskList. here is my code:

$client = getClient();
$service = new Google_Service_Tasks($client);

$optParams = array('maxResults' => 10);

$serviceTasklist = $service->tasklists->listTasklists($optParams);

$serviceTask = $service->tasks->listTasks("@default", $optParams);

try {
    $task = new Google_Service_Tasks_Task();
    $task->setTitle("here is new task");
    $task->setNotes("this is note of new task");

    $result = $service->tasks->insert("@default", $task);
    return $result->getId();

} catch (Google_Exception $ggex) {
    echo "\n Error: " . $ggex->getMessage();
}

I had tried to change scope from Google_Service_Task::TASK_READONLY to Google_Service_Task::TASK, included google task document also do a samething, but I tried then it not work . Can someone give my suggest or tell me know where am I wrong? Thank You !.

Minh Trung
  • 15
  • 8
  • Have you recreated the token after you changed the scopes in code? Meaning if you store the token locally and you want to change the scopes you need to recreate that token, so make sure you have done that. – Raserhin May 28 '20 at 08:34
  • ok, followed your idea and it work. – Minh Trung May 28 '20 at 13:03

1 Answers1

0

For documentation purpose:

The problem was in the token file itself. When you change the scopes you need to make sure to get a new updated token. If you still use the previous token is like haven't changed your code at all.

Raserhin
  • 2,516
  • 1
  • 10
  • 14