PHP file_get_contents 和体式 API

PHP file_get_contents and Asana API

我正在尝试从我们的体式工作区中检索一些值。

我已经用 javascript

做到了
var bearerToken = "bearer APIKEY";
    var requestUrl = "https://app.asana.com/api/1.0/projects/PROJECTID/tasks"
     var headers = {
      "Authorization" : bearerToken

    };

    var reqParams = {
        method : "GET",
        headers : headers,
        muteHttpExceptions: true
      };

    let res= await fetch(requestUrl,reqParams); // (2)

但出于安全原因,我正在尝试将此代码转换为 PHP,因此:

$url = 'http://app.asana.com/api/1.0/projects/PROJECTID/tasks';


$opts = [
    "http" => [
        "method" => "GET",
        "header" => "Content-Type: application/json\r\n" .
            "charset=utf-8\r\n" ,
            "Authorization : bearer APIKEY \r\n"
    ]
];

$context = stream_context_create($opts);


$file = file_get_contents('app.asana.com/api/1.0/projects/1158939083333529/tasks', false, $context);

$file = file_get_contents($url, false, $context);
$json_echo = json_decode($file)
 echo $json_echo;

回显将return空值...

此致

这里有一个完整的功能代码,供可能需要它的任何人使用:

$WCURL = 'https://app.asana.com/api/1.0/projects/projetc_id/tasks';
$CURLHTTPHeader = array(
    'Content-Type: application/json',
    'Accept: application/json',
    'Authorization: Bearer your_api_key');

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$WCURL);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER,$CURLHTTPHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlResponse = curl_exec ($ch);
curl_close ($ch);

echo $curlResponse;