0

Spent hours and cannot seem to understand what went wrong with my Google Tasks API.

  1. Created new project in GCP
  2. Enable Google Tasks API
  3. Added a key and downloaded services-account.json
  4. Using the official Google Client PHP library
  5. Managed to authenticate and getting a response from Google Tasks API.

But it doesn't return the correct Google Tasks and Tasklist ID from my account.

The response returned the ID value which I validated with the Google Tasks API Resource - Try this API and the ID inputted resulted Invalid ID. Tried with the Try this API and authenticate my account and the Task ID is not the same with what I got from the Google Client PHP library.

Hoping someone can shed some lights. Thanks in advance.

public function google_test() {
    $client = new Google\Client();
    $token = plugin_dir_path( __FILE__ ) . 'credentials.json';
    $client->setApplicationName('Google Tasks API PHP Quickstart');
$client->setScopes(Google_Service_Tasks::TASKS_READONLY);
    $client->setAuthConfig( $token );

    // Get the API client and construct the service object.
    $service = new Google_Service_Tasks($client);

    // Print the first 10 task lists.
    $optParams = array(
      'maxResults' => 99,
    );
    $results = $service->tasklists->listTasklists($optParams);

    foreach ($results->getItems() as $tasklist) {
        $tasklist_id = $tasklist->getId();
        $tasks = $service->tasks->listTasks($tasklist_id, $optParams);
        $all_tasks[]        = $tasks->getItems();
}
    return $all_tasks;
}

Payload returned

O:30:"Google_Service_Tasks_TaskLists":10:{s:17:"��collection_key";s:5:"items";s:4:"etag";s:17:""LTE2NTQyOTQ1NDc"";s:12:"��itemsType";s:29:"Google_Service_Tasks_TaskList";s:16:"��itemsDataType";s:5:"array";s:4:"kind";s:15:"tasks#taskLists";s:13:"nextPageToken";N;s:25:"��internal_gapi_mappings";a:0:{}s:12:"��modelData";a:0:{}s:12:"��processed";a:0:{}s:5:"items";a:1:{i:0;O:29:"Google_Service_Tasks_TaskList":9:{s:4:"etag";s:16:""MTg1ODI2Mzc1MQ"";s:2:"id";s:32:"MTgxMDkzOTg1ODk3OTkzMTUxODI6MDow";s:4:"kind";s:14:"tasks#taskList";s:8:"selfLink";s:84:"https://www.googleapis.com/tasks/v1/users/@me/lists/MTgxMDkzOTg1ODk3OTkzMTUxODI6MDow";s:5:"title";s:8:"My Tasks";s:7:"updated";s:24:"2021-03-26T13:39:27.312Z";s:25:"��internal_gapi_mappings";a:0:{}s:12:"��modelData";a:0:{}s:12:"�*�processed";a:0:{}}}}

Google Tasks API Explorer

{ "kind": "tasks#taskLists", "etag": ""LTExMDA5MDAxOQ"", "items": [ { "kind": "tasks#taskList", "id": "MDgyMDgxNjM3NzQxMDkxMjA0Mzk6MDow", "etag": ""MTg1NTU3NTU1OQ"", "title": "My Tasks", "updated": "2021-03-26T12:54:38.480Z", "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/MDgyMDgxNjM3NzQxMDkxMjA0Mzk6MDow" }, { "kind": "tasks#taskList", "id": "SldJSG1BUU53RjFmRkRlMg", "etag": ""MTg0NDkwMTM4Nw"", "title": "Jazlyn's Tasks", "updated": "2021-03-26T09:56:44.308Z", "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/SldJSG1BUU53RjFmRkRlMg" }, { "kind": "tasks#taskList", "id": "Y1JNZUtBUDJXb1psMk5WNg", "etag": ""LTIzMTA5MjU2MQ"", "title": "Anneke's Tasks", "updated": "2021-03-02T09:16:51.047Z", "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/Y1JNZUtBUDJXb1psMk5WNg" }, { "kind": "tasks#taskList", "id": "M0ozM2VjekRWdDBYaHVuMA", "etag": ""MzY4Njg4NTM2"", "title": "Richard's Tasks", "updated": "2021-03-09T07:53:11.425Z", "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/M0ozM2VjekRWdDBYaHVuMA" }, { "kind": "tasks#taskList", "id": "NjlpcFpUVm5iYy02M2o1Sg", "etag": ""MTQxNzA5OTA3Nw"", "title": "Calvin's Tasks", "updated": "2021-03-21T11:06:42.142Z", "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/NjlpcFpUVm5iYy02M2o1Sg" }, { "kind": "tasks#taskList", "id": "c184LVhIZXB3N0Zva1Jndg", "etag": ""MTg1NTg0MDAzNg"", "title": "Test", "updated": "2021-03-26T12:59:03.165Z", "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/c184LVhIZXB3N0Zva1Jndg" } ] }

Calvin Seng
  • 193
  • 1
  • 19
  • Could you please provide your code to verify if there's an issue in your code? and the error you encountered when validating the task id response when tried in the Google Tasks API Explorer – Ron M Mar 26 '21 at 17:42
  • Hi Ron, added them to the original question. Thanks! – Calvin Seng Mar 27 '21 at 02:01
  • Hi, were you able to find a solution to this issue? I am facing the same.... – madhall Jun 28 '21 at 13:37
  • Sorry to hear that but I wasn't able to reproduce your issue when I tried in on my side – Ron M Jun 28 '21 at 15:48
  • Hi Ron, these are the steps to recreate -> 1) Sync Tasks with Google Tasks using Tasks API 2) Verify the ID received for TaskList or Task on the API Explorer - for Google Tasks - Update Section 3) It will inform that the TaskList ID or Task ID is missing – madhall Jun 29 '21 at 07:27
  • You can create a ticket for this issue in https://issuetracker.google.com/ – Ron M Jun 29 '21 at 15:49

0 Answers0