2017-01-06 11 views
0

私はトークン($トークンに保持されている文字列)を持っており、カールを使用してオンラインサービスから応答(JSON)を取得する必要があります。認証ヘッダートークン付きカール - GET - PHP

APIにはGETが必要です。 $の残りのダンプ

$crl = curl_init(); 

$headr = array(); 
$headr[] = 'Content-length: 0'; 
$headr[] = 'Content-type: application/json'; 
$headr[] = 'Authorization: OAuth '.$token; 

curl_setopt($crl, CURLOPT_HTTPHEADER,$headr); 
$url = "ENDPOINT"; 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_HTTPGET, 1); 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$rest = curl_exec($crl); 

curl_close($crl); 

var_dump($rest); 

は私を与える:

bool(false) 

私はあなたが変数名、すなわち混合され、このthread

+0

'エコーcurl_error($のCRL)'何と言っています:それは助け場合

が、これはあなたのコードを実行しているとき、私はローカルに取得しています何ですか? – Barmar

+0

エラー:URLが設定されていません! –

+0

これは奇妙です - URLは$ urlに設定されました –

答えて

2

に上記をベース。 $crl$chは、それをきれいにしてください。少なくとも偽でなければなりません。

あなたのphp.inienable error_reportingもお勧めします。開発中のコードでこのようなバグを見つけやすくなります。

PHP Notice: Undefined variable: ch in /home/sebastianforsberg/env/test.php on line 13 
PHP Warning: curl_setopt() expects parameter 1 to be resource, null given in /home/sebastianforsberg/env/test.php on line 13 
PHP Notice: Undefined variable: ch in /home/sebastianforsberg/env/test.php on line 14 
PHP Warning: curl_setopt() expects parameter 1 to be resource, null given in /home/sebastianforsberg/env/test.php on line 14 
PHP Notice: Undefined variable: ch in /home/sebastianforsberg/env/test.php on line 16 
PHP Warning: curl_setopt() expects parameter 1 to be resource, null given in /home/sebastianforsberg/env/test.php on line 16 
bool(false) 
関連する問題