Search code examples
phpgoogle-tasks-apigoogle-tasks

Insert Task in Google Task API , Error: 403, message: Request had insufficient authentication scopes


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 !.


Solution

  • 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.