`php `php
code> pre>
<?php p>
require_once ‘/path/to/vendor/autoload.php’;
require_once‘/path/to/vendor/autoload.php’; p>
// 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’);
$ authenticator = new \ ActiveCollab \ SDK \ Authenticator \ Cloud(“ ACME Inc”,“ My Awesome Application”,“ you@acmeinc.com”,“难以猜测,易于记忆”); p>
// Show all Active Collab 5 and up account that this user has access to.
//显示该用户有权访问的所有Active Collab 5及更高版本的帐户。
print_r($authenticator->getAccounts());
print_r($ authenticator-> getAccounts()); p>
// Show user details (first name, last name and avatar URL).
//显示用户详细信息(名字,姓氏和头像URL)。
print_r($authenticator->getUser());
print_r($ authenticator-> getUser()); p>
// Issue a token for account #123456789.
//为帐户#123456789发行令牌。
$token = $authenticator->issueToken(123456789);
$ token = $ authenticator-> issueToken(123456789); p>
// Did we get it?
//我们明白了吗?
if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
if($ token instanceof \ ActiveCollab \ SDK \ TokenInterface){
print $token->getUrl() .
打印$ token-> getUrl()。
“\n”;
“ \ n”;
print $token->getToken() .
打印$ token-> getToken()。
“\n”;
“ \ n”;
} else {
} else {
print “Invalid response\n”;
打印“无效的响应\ n”;
die();
die();
}
}
Connecting to Self-Hosted Active Collab Accounts
php
连接到自托管的Active Collab帐户 h3> code> php
require_once ‘/path/to/vendor/autoload.php’;
require_once‘/path/to/vendor/autoload.php’; p>
// Provide name of your company, name of the app that you are developing, your email address and password.
//提供您的公司名称,正在开发的应用程序的名称,您的电子邮件地址和密码。
Last parameter is URL where your Active Collab is installed.
最后一个参数是安装Active Collab的URL。
$authenticator = new \ActiveCollab\SDK\Authenticator\SelfHosted('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember', 'https://my.company
$ authenticator = new \ ActiveCollab \ SDK \ Authenticator \ SelfHosted('ACME Inc','My Awesome Application','you@acmeinc.com','难以猜测,易于记忆','https://my.company
.com/projects');
.com / projects'); p>
// Issue a token.
//发行令牌。
$token = $authenticator->issueToken();
$ token = $ authenticator-> issueToken(); p>
// Did we get what we asked for?
//我们得到了我们想要的东西吗?
if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
if($ token instanceof \ ActiveCollab \ SDK \ TokenInterface){
print $token->getUrl() .
打印$ token-> getUrl()。
“\n”;
“ \ n”;
print $token->getToken() .
打印$ token-> getToken()。
“\n”;
“ \ n”;
} else {
} else {
print “Invalid response\n”;
打印“无效的响应\ n”;
die();
die();
}
}
`
` p>
SSL problems?
SSL问题? h3>
If curl complains that SSL peer verification has failed, you can turn it off like this:
如果curl抱怨SSL对等验证失败,则可以这样关闭它: p>
`php `php
code> pre>
// Cloud
//云
$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud(‘ACME Inc’, ‘My Awesome Application’, ‘you@acmeinc.com’, ‘hard to guess, easy to remember’, false);
$ authenticator = new \ ActiveCollab \ SDK \ Authenticator \ Cloud(“ ACME Inc”,“ My Awesome Application”,“ you@acmeinc.com”,“难以猜测,易于记忆”,错误);
$authenticator->setSslVerifyPeer(false);
$ authenticator-> setSslVerifyPeer(false); p>
// Self-hosted
//自托管
$authenticator = new \ActiveCollab\SDK\Authenticator\SelfHosted('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember', 'https://my.company
$ authenticator = new \ ActiveCollab \ SDK \ Authenticator \ SelfHosted('ACME Inc','My Awesome Application','you@acmeinc.com','难以猜测,易于记忆','https://my.company
.com/projects', false);
.com / projects',false);
$authenticator->setSslVerifyPeer(false);
$ authenticator-> setSslVerifyPeer(false); p>
// Client
//客户端
$client = new \ActiveCollab\SDK\Client($token);
$ client = new \ ActiveCollab \ SDK \ Client($ token);
$client->setSslVerifyPeer(false);
$ client-> setSslVerifyPeer(false);
`
` p>
Note: Option to turn off SSL peer verification has been added in Active Collab SDK 3.1.
注意 strong>:已在Active Collab SDK 3.1中添加了用于关闭SSL对等验证的选项。 p>Constructing a client instance
构建客户端实例 h3>
Once we have our token, we can construct a client and make API calls:
有了令牌后,我们就可以构建一个客户端并进行API调用: p>
`php `php
code> pre>
$client = new \ActiveCollab\SDK\Client($token);
$ client = new \ ActiveCollab \ SDK \ Client($ token);
`
` p>
Listing all tasks in project #65 is easy.
列出项目65中的所有任务很容易。
Just call:
只需致电: p>
`php `php
code> pre>
$client->get(‘projects/65/tasks’);
$ client-> get(‘projects / 65 / tasks’);
`
` p>
To create a task, simply send a POST request:
要创建任务,只需发送一个POST请求: p>
`php `php
code> pre>
try {
尝试{
$client->post(‘projects/65/tasks’, [
$ client-> post(“ projects / 65 / tasks”,[
‘name’ => ‘This is a task name’,
‘name’=>‘这是一个任务名称’,
‘assignee_id’ => 48
‘assignee_id’=> 48
]);
]);
} catch(AppException $e) {
} catch(AppException $ e){
print $e->getMessage() .
打印$ e-> getMessage()。
‘
‘ p>
‘;
’;
// var_dump($e->getServerResponse());
// var_dump($ e-> getServerResponse());
(need more info?)
(需要更多信息吗?)
}
}
`
` p>
To update a task, PUT request will be needed:
要更新任务,需要PUT请求: p>
`php `php
code> pre>
try {
尝试{
$client->put(‘projects/65/tasks/123’, [
$ client-> put('projects / 65 / tasks / 123',[
‘name’ => ‘Updated named’
‘name’=>‘Updated named’
]);
]);
} catch(AppException $e) {
} catch(AppException $ e){
print $e->getMessage() .
打印$ e-> getMessage()。
‘
‘ p>
‘;
’;
// var_dump($e->getServerResponse());
// var_dump($ e-> getServerResponse());
(need more info?)
(需要更多信息吗?)
}
}
`
` p>
post()`` and ``put()`` methods can take two arguments: post()``和``put()``方法可以使用两个参数:
code> pre>
command
(required) – API command,-
命令 code>(必填)– API命令, li>variables
– array of request variables (payload)-
变量 code> –请求变量(有效载荷)数组 li>
ol>
To remove a task, call:
要删除任务,请致电: p>
`php `php
code> pre>
try {
尝试{
$client->delete(‘projects/65/tasks/123’);
$ client-> delete(‘projects / 65 / tasks / 123’);
} catch(AppException $e) {
} catch(AppException $ e){
print $e->getMessage() .
打印$ e-> getMessage()。
‘
‘ p>
‘;
’;
// var_dump($e->getServerResponse());
// var_dump($ e-> getServerResponse());
(need more info?)
(需要更多信息吗?)
}
}
`
` p>
delete()`` method only requires ``command`` argument to be provided. delete()``方法仅需要提供“ command”参数。
code> pre>
For full list of available API command, please check Active Collab API documentation.
有关可用API命令的完整列表,请查看 Active Collab API文档。 p>
p>
>