【问题标题】:How to Return List of Project Tasks in ActiveCollab如何在 ActiveCollab 中返回项目任务列表
【发布时间】:2021-04-16 20:42:49
【问题描述】:

对不起,这可能是一个微不足道的问题,但我是 PHP 新手。在documentation检索项目任务中,提供了以下代码连接到一个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 对象)?

提前致谢。

【问题讨论】:

    标签: php api activecollab


    【解决方案1】:

    有几种方法可以处理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"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      相关资源
      最近更新 更多