2015-02-11 51 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,這不是有效的工作空間,這可能至少是問題的一部分。