php - 如何在 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 对象)?
提前致谢。
解决方案
有几种使用 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"
}
}
推荐阅读
- java - Java 11 的 Nashorn 替代方案
- java - Java方法覆盖equals方法
- laravel - 数据表 - Yajra 返回不正确的字符串 - Laravel 5.8
- git - Azure devops 跳过构建管道
- algorithm - 一维点的成对距离
- python - 我如何知道我的网络摄像头当前是否正常工作?蟒蛇,opencv
- kotlin - 强制为非空而不使用?
- c# - 是否有直接的方法将容器日志从物联网边缘设备发送到 Azure 日志分析工作区?
- winforms - Infragistics UltraToolbarsManager - 将 ApplicationDefaults 添加到 QuickAccessToolbar
- javascript - JavaScript:undefined++的结果是NaN,不是undefined?