Google Task API Insert task

Can anybody write me an example to use the function testInsertTask()
at here: (This contains the offical library of Google task api)
https://github.com/google/google-api-php-client/blob/master/tests/tasks/TasksTest.php


I have managed to LIST THE TASKS with the below script. But cannot insert, I have tried something at the very below

<?php


include_once "google-api-php-client-master/examples/templates/base.php";


set_include_path("google-api-php-client-master/src/" . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once 'Google/Service/Tasks.php';
require_once 'Google/Service/Calendar.php';

/************************************************
  ATTENTION: Fill in these values! Make sure
  the redirect URI is to this page, 
 ************************************************/
$client_id = '72327291fffffffffffeusercontent.com';
 $client_secret = 'ssssssssssssssss';
 $redirect_uri = 'dddddddddd';


/************************************************
  Make an API request on behalf of a user. In
  this case we need to have a valid OAuth 2.0
  token for the user, so we need to send them
  through a login flow. To do this we need some
  information from our API console project.
 ************************************************/
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/tasks");
$client->addScope("https://www.googleapis.com/auth/calendar");

/************************************************
  We are going to create  services, 
 ************************************************/
$task_service = new Google_Service_Tasks($client);
$calendar_service = new Google_Service_Calendar($client);


/************************************************
  Boilerplate auth management - see
  user-example.php for details.
 ************************************************/
if (isset($_REQUEST['logout'])) {
  unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

 if($rest['TOKEN1']) {

  $_SESSION['access_token']=$rest['TOKEN1'];		
  $client->setAccessToken($_SESSION['access_token']);
	

}else {
  $authUrl = $client->createAuthUrl();
  header("Location:".$authUrl);
}



/************************************************
  If we're signed in, retrieve 
 ************************************************/
if ($client->getAccessToken()) {
  $_SESSION['access_token'] = $client->getAccessToken();


  
	$tasks = $task_service->tasks->listTasks('@default');
    echo "<h3>Results Of Task List:</h3>";
    foreach($tasks->getItems() as $task) {
	echo $task->getTitle();
	}

 
$task = $task_service->tasks->__construct();
$task->setTitle('New Task');
$task->setNotes('Please complete me');
$task->setDue(new TaskDateTime('2010-10-15T12:00:00.000Z'));

$result = $task_service->insertTasks('@default', $task);
echo $result->getId();


  
  
  
 }

    

    
 ?>

Open in new window

LVL 1
myyisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BlueComputeCommented:
Your code's become mangled somewhere along the line; does your actual code say:
task->setTitle('New Task');

Open in new window

Or does it say:
task->setTitle('New Task');

Open in new window

?

I'm assuming that's just an error that's been introduced when you copy-pasted and have corrected it in the version I have.

I'm also not clear on why you're trying to actually call the TasksTest.php samples - they're intended as demonstrations of how to use the API, they don't form part of it. What you should be doing is basing your code on the code in the samples - a cursory examination suggests to create a new task and add it to a list you do:
$tasks = $this->taskService->tasks; // Get a handle to our tasks
$task = new Google_Service_Tasks_Task(); // Create a new task object
$task->title = "New Task"; //Set the title
$task->notes = "Please complete me"; //Set the notes
$task->due = (new TaskDateTime('2010-10-15T12:00:00.000Z')); //Add a due date
$tasks->insert('@default', $task) // Insert the task into the default tasklist

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
myyisAuthor Commented:
That worked. Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.