2015-02-11 47 views
0

我使用的体位API PHP类来创建任务时,在这里举行:https://github.com/ajimix/asana-api-php-class快速响应码400尝试使用API​​

,我使用他们的几乎确切的示例代码:

<?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' => '[email protected]', // 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; 
    } 

变化我做这个原代码:

  1. 我从我的体位法的API密钥,所以我假设它应该是没有错,并把它的apiKey数组索引
  2. 0123内
  3. 我实际上并不知道工作区ID是什么,但我项目的URL格式为https://app.asana.com/{integer}/{integer}/{integer},所以我使用第一个整数作为$workspaceId,第二个整数(与第三个整数相同)作为$projectId。我使用第二个整数为$projectId都和$workspaceId用同样的结局
  4. 我把我自己的体位电子邮件assignee数组索引下的createTask()通话
  5. 我从createTask()呼叫
  6. 删除 followers阵列项目还试图

只有这些更改,然后运行此代码,我得到Error while trying to connect to Asana, response code: 400。在Asana页面上没有更多错误代码解释或FAQ。可能是什么问题呢?

回答

0

网址体位的形式为0/{project}/{task or project}的(典型值) - 如果你想知道你的工作空间ID,您应该GET /workspaces当前用户 - 这会给你的工作空间的当前用户是在一个列表,以及工作区的名称和工作区ID。

当请求发生错误时,我们会返回一个400错误请求 - 不幸的是,您使用的PHP库似乎没有将错误从Asana传递回给您:-(但是,假设第一个整数路径为0,这不是有效的工作空间,这可能至少是问题的一部分。