首页 > 解决方案 > 如何在 ActiveCollab 中返回项目任务列表

问题描述

抱歉,这可能是一个微不足道的问题,但我是 PHP 新手。在检索项目任务的文档中,提供了以下代码以连接到 Active Collab 云帐户:

<?php

require_once '/path/to/vendor/autoload.php';

// Provide name of your company, name of the app that you are developing, your email address and password.
$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember');

// Show all Active Collab 5 and up account that this user has access to.
print_r($authenticator->getAccounts());

// Show user details (first name, last name and avatar URL).
print_r($authenticator->getUser());

// Issue a token for account #123456789.
$token = $authenticator->issueToken(123456789);

// Did we get it?
if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
    print $token->getUrl() . "\n";
    print $token->getToken() . "\n";
} else {
    print "Invalid response\n";
    die();
}

这工作正常。然后我可以创建一个客户端来进行 API 调用:

$client = new \ActiveCollab\SDK\Client($token);

并获取给定项目的任务列表,如文档中所示。

$client->get('projects/65/tasks'); // PHP object

我的问题是,有哪些方法/属性可用于获取任务列表?print_r()我可以使用(显然不会工作)打印对象print,而我真正想要的是在raw_response标题中。但是这是私人的,我无法访问它。我如何实际获取任务列表(例如:raw_response有一个字符串或 json 对象)?

提前致谢。

标签: phpapiactivecollab

解决方案


有几种使用 body 的方法:

$response = $client->get('projects/65/tasks');

// Will output raw JSON, as string.
$response->getBody();

// Will output parsed JSON, as associative array.
print_r($response->getJson());

有关可用响应方法的完整列表,请查看ResponseInterface

如果您希望循环执行任务,请使用以下内容:

$response = $client->get('projects/65/tasks');
$parsed_json = $response->getJson();

if (!empty($parsed_json['tasks'])) {
    foreach ($parsed_json['tasks'] as $task) {
        print $task['name'] . "\n"
    }
}

推荐阅读