尝试检索project PHP Asana类时出错

尝试检索project PHP Asana类时出错,php,api,error-code,asana,Php,Api,Error Code,Asana,我用它来获取项目及其任务。我成功地完成了这个项目。但当试图获得任务时,它会返回 Error while trying to connect to Asana, response code: 400 下面是代码,它完全来自示例。当asana在另一个示例中返回项目代码时,我得到了项目代码,我可以从中获得项目列表 <?php require_once("../asana.php"); // See class comments and Asana API for full info $as

我用它来获取项目及其任务。我成功地完成了这个项目。但当试图获得任务时,它会返回

Error while trying to connect to Asana, response code: 400
下面是代码,它完全来自示例。当asana在另一个示例中返回项目代码时,我得到了项目代码,我可以从中获得项目列表

<?php
require_once("../asana.php");

// See class comments and Asana API for full info

$asana = new Asana("xxxxxxxxxxxxxxxxx"); 

// Your API Key, you can get it in Asana
$projectId = 'xxxxxxxxxxxxx'; // Your Project ID Key, you can get it in Asana

$result = $asana->getProjectTasks($projectId);

// As Asana API documentation says, when response is successful, 
we receive a 200 in response so...

if($asana->responseCode == "200" && !is_null($result)){
    $resultJson = json_decode($result);

    var_dump($resultJson);

} else {
    echo "Error while trying to connect to Asana, response code: {$asana->responseCode}";
}

您的项目ID很可能不正确。通过回显项目ID并在Asana中签入,确保您获取了正确的项目ID(在Asana中查看项目/任务时,这是url中的第一个长数字)

$tasks = $asana->getProjectTasks($project_ID); //got the $project_ID directly from the url in Asana. $tasksJson = json_decode($tasks); if($asana->responseCode == "200" && !is_null($tasks)){ foreach ($tasksJson->data as $task){ echo "+ " . $task->name . " (id " . $task->id . ")" . " ]
"; } } else { echo "Error while trying to connect to Asana, response code: {$asana->responseCode}"; } 一旦您验证了项目ID是正确的,您的代码应该可以工作。我验证了下面的代码是否适用于我

下面是我用来获取任务列表的确切代码:

$tasks=$asana->getProjectTasks($project\u ID)//直接从Asana中的url获取$project_ID。 $tasksJson=json_decode($tasks); 如果($asana->responseCode==“200”&&!为空($tasks)){ foreach($tasksJson->data as$task){ 回显“+”$task->name.”(id“$task->id.”“)”]
”; $tasks = $asana->getProjectTasks($project_ID); //got the $project_ID directly from the url in Asana. $tasksJson = json_decode($tasks); if($asana->responseCode == "200" && !is_null($tasks)){ foreach ($tasksJson->data as $task){ echo "+ " . $task->name . " (id " . $task->id . ")" . " ]
"; } } else { echo "Error while trying to connect to Asana, response code: {$asana->responseCode}"; } } }否则{ echo“尝试连接到Asana时出错,响应代码:{$Asana->responseCode}”; $tasks = $asana->getProjectTasks($project_ID); //got the $project_ID directly from the url in Asana. $tasksJson = json_decode($tasks); if($asana->responseCode == "200" && !is_null($tasks)){ foreach ($tasksJson->data as $task){ echo "+ " . $task->name . " (id " . $task->id . ")" . " ]
"; } } else { echo "Error while trying to connect to Asana, response code: {$asana->responseCode}"; } }
不要打印您自己的错误消息,请尝试在
$result
上执行
var\u dump
,如果它为null或不包含任何有用的信息,请编辑该类并将debug切换到on以查看发生了什么。正如API文档中所述,400响应代码表示您的请求格式不正确。