Solved

Google Task API Insert task

Posted on 2014-09-10
4
550 Views
Last Modified: 2014-09-16
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

0
Comment
Question by:myyis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Accepted Solution

by:
BlueCompute earned 500 total points
ID: 40325085
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
 

Author Closing Comment

by:myyis
ID: 40325114
That worked. Thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question