1

我试图弄清楚如何使用 Google 任务 API 添加任务。文档留下了很多要调查的东西,我看到被卡住了。这是我的代码:

// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Tasks($client);
...
... get token etc...
...
// Create a task
$task = new Google_Service_Tasks_Task();
$task->setTitle("Call mum");
$task->setNotes("Inserted by app");
$task->setStatus("needsAction");
$task->setDue(new DateTime('2020-01-01T00:00:01.000Z'));
// constructor needs 4 params: service, serviceName, resourceName, resource
$res = new Google_Service_Tasks_Resource_Tasks('', '', '', '');
$res->insert($lastListID, $task);

创建新的 Google_Service_Tasks_Resource_Tasks(倒数第二行)时,我需要向构造函数提供 4 个参数:service、serviceName、resourceName、resource。我找不到任何解释最后三个参数的文档。我使用这个类是因为它有一个插入方法,我认为这是我需要的。这些例子都停留在列出任务(作品)上。我试着理解这些文档:

我无法理解供应商目录中的实际类。有谁知道如何驯服这个API?

4

1 回答 1

0

我了解到您想使用 PHP Tasks API 创建一个任务。您的方法是正确的,您只需要使用带有三个参数而不是四个参数的构造函数。正如我们在Google_Service_Tasks_Resource_Tasks文档中看到的,insert 操作定义为:

  /**
   * Creates a new task on the specified task list. (tasks.insert)
   *
   * @param string $tasklist Task list identifier.
   * @param Google_Service_Tasks_Task $postBody
   * @param array $optParams Optional parameters.
   *
   * @opt_param string parent Parent task identifier. If the task is created at
   * the top level, this parameter is omitted. Optional.
   * @opt_param string previous Previous sibling task identifier. If the task is
   * created at the first position among its siblings, this parameter is omitted.
   * Optional.
   * @return Google_Service_Tasks_Task
   */
  public function insert($tasklist, Google_Service_Tasks_Task $postBody, $optParams = array())
  {
    $params = array('tasklist' => $tasklist, 'postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('insert', array($params), "Google_Service_Tasks_Task");
  }

该评论将三个参数定义为:

  1. 任务列表标识符。这是在其资源id上定义的任务列表。
  2. 要创建的任务对象的内容,如代码中的内容。
  3. 包含两个元素的可选对象:
    1. 父任务标识符。该元素id资源文档中被调用。如果任务没有父任务,该参数可以省略。
    2. 上一个兄弟任务。此元素与前一点相同,但引用列表的前一个元素。如果新元素将是其兄弟元素之间的第一个元素(或者它将是唯一的元素),则可以省略此参数。

一个基于代码变量的工作示例将是:

$optParams = array("{PARENT TASK ID}", "{PREVIOUS TASK ID}");
$res = new Google_Service_Tasks_Resource_Tasks();
$res->insert($taskListID, $task, $optParams);

使用此方法,您可以使用您的方法创建任务。如果您有任何问题,请不要犹豫,要求进一步澄清。

于 2019-12-02T09:43:32.333 回答