2013-08-23 54 views
1

我現在正在調試這個問題兩天,但我找不到任何此代碼的問題。請指導我做錯了什麼?通過URL時發出捲曲警告

<?php 

$curl = curl_init(); 

curl_setopt_array($curl, array(
    'CURLOPT_RETURNTRANSFER' => 1, 
    'CURLOPT_URL'    => 'https://api.instagram.com/v1/users/self/feed?access_token=' . $tocken, 
    )); 

$respond = curl_exec($curl); 

if(!$respond){ 
    echo curl_error($curl); 
    exit; 
} 

curl_close($curl); 

var_dump(json_decode($respond, true)); 

我得到這個錯誤。

警告:curl_setopt_array()[function.curl-SETOPT陣列]:數組密鑰必須在/home/..../test.php CURLOPT常量或等效的整數值在第8行未 URL集!

回答

9

您的數組鍵必須是常量,而不是字符串。刪除引用:

curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1, 
CURLOPT_URL    => 'https://api.instagram.com/v1/users/self/feed?access_token=' . $tocken, 
)); 
+0

謝謝...你代表超過100現在確定.. :) – Namal

+0

不要做:$ curlOptions [ 「CURLOPT_POSTFIELDS」] = $的數據; – kodmanyagha

2

您不應該引用CURLOPT常量,因爲它們是常量,而不是字符串。作爲固定fowllowing:

<?php 
$curl = curl_init(); 

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1, //notice, if your PHP > 5.1.3, no need to use this opt 
    CURLOPT_URL   => 'https://api.instagram.com/v1/users/self/feed?access_token=' . $tocken, 
));