我使用的是Asana API PHP类,托管在这里:https://github.com/ajimix/asana-api-php-class
我正在使用他们几乎精确的示例代码:
<?php
// See class comments and Asana API for full info
$asana = new Asana(array('apiKey' => 'xxxxxxxxxxxxxxxxxxxxxxxx')); // Your API Key, you can get it in Asana
$workspaceId = 'XXXXXXXXXXXXXXXXXXX'; // The workspace where we want to create our task
$projectId = 'XXXXXXXXXXXXXXXXXXX'; // The project where we want to save our task
// First we create the task
$result = $asana->createTask(array(
'workspace' => $workspaceId, // Workspace ID
'name' => 'Hello World!', // Name of task
'assignee' => 'bigboss@bigcompany.com', // Assign task to...
'followers' => array('XXXXX', 'XXXXXXXX') // We add some followers to the task... (this time by ID), this is totally optional
));
// As Asana API documentation says, when a task is created, 201 response code is sent back so...
if ($asana->responseCode != '201' || is_null($result)) {
echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
return;
}
$resultJson = json_decode($result);
$taskId = $resultJson->data->id; // Here we have the id of the task that have been created
// Now we do another request to add the task to a project
$result = $asana->addProjectToTask($taskId, $projectId);
if ($asana->responseCode != '200') {
echo 'Error while assigning project to task: ' . $asana->responseCode;
}
我对此原始代码所做的更改:
apiKey
数组索引https://app.asana.com/{integer}/{integer}/{integer}
,所以我使用第一个整数作为$workspaceId
和第二个整数一个(与第三个相同)和$projectId
。我也尝试使用第二个整数作为$projectId
和$workspaceId
具有相同的结果assignee
电话createTask()
数组索引下放了我自己的Asana电子邮件
followers
调用createTask()
数组项
醇>
只有这些更改,然后运行此代码,我得到Error while trying to connect to Asana, response code: 400
。在Asana页面上没有进一步的错误代码说明或常见问题解答。可能是什么问题呢?
答案 0 :(得分:0)
0/{project}/{task or project}
- 如果您想知道自己的工作区ID,则应GET /workspaces
作为当前用户 - 这将为您提供工作区列表当前用户以及工作区名称和工作区ID。
当请求出现问题时,我们会返回400 Bad Request - 遗憾的是,您正在使用的PHP库似乎没有将Asana的错误传回给您:-(但是,鉴于第一个整数路径中的0是非有效工作空间,可能至少是问题的一部分。