我試圖讓我的訪問令牌在Twitter的API: https://dev.twitter.com/oauth/application-only捲曲後頭球PHP
我在使用PHP捲曲,我沒有得到的結果!
我的代碼:
$consumer_key = "XXXXXXXX";
$consumer_secret = "XXXXXXXX";
$base64 = base64_encode($consumer_key.':'.$consumer_secret);
$data = array("grant_type" => "client_credentials");
$header = array(
"Authorization" => "Basic $base64",
"Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8",
"Accept-Encoding" => "gzip",
);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://api.twitter.com/oauth2/token');
curl_setopt ($curlObj, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curlObj);
$json = json_decode($response, true);
curl_close($curlObj);
print_r($json);
問題出在哪裏?
你只是假設成功。 curl_exec在失敗時返回布爾值false。 'if($ response === false){die(curl_error($ curlObj)); }' –