1

我正在使用 PHP 7.2 和 cURL 7.53.1。我正在尝试使用 Google 的 NEST REST API。

我尝试这样的 CURL 请求:

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://developer-api.nest.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_FOLLOWLOCATION=>true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "Authorization: Bearer ".$authkey,
  ),
  CURLINFO_HEADER_OUT=>true
));

$response = curl_exec($curl);
var_dump($response);
var_dump(curl_getinfo($curl, CURLINFO_HEADER_OUT));

我看到了这个:

string(181) "{"error":"unauthorized","type":"https://developer.nest.com/documentation/cloud/error-messages#auth-error","message":"unauthorized","instance":"63d53235-5548-4d4f-b791-360c53baef4a"}"
string(165) "GET / HTTP/1.1
Host: firebase-apiserver14-tah01-iad01.dapi.production.nest.com:9553
Accept: */*
Accept-Encoding: deflate, gzip
Content-Type: application/json

"

对 developer-api.nest.com 的请求似乎已重定向到 firebase-apiserver14-tah01-i​​ad01.dapi.production.nest.com:9553。好的...但是在随后的请求中,cURL 没有发送 Authorization 标头。奇怪的是,它正在发送 Content-type 标头...

请求失败,因为它未经授权。

任何帮助表示赞赏。干杯

4

0 回答 0