Spent hours and cannot seem to understand what went wrong with my Google Tasks API.
- Created new project in GCP
- Enable Google Tasks API
- Added a key and downloaded services-account.json
- Using the official Google Client PHP library
- 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" } ] }