所以我试图从 bit.ly 检索 access_token 以使用他们的 url 缩短 API 调用。每次我进行 curl 调用时,我都会收到 INVALID_CLIENT_ID 作为响应。我检查了四次,我所有的钥匙都很好。会发生什么?
这是代码:
define('BITLY_CLIENT_ID','xxx');
define('BITLY_CLIENT_SECRET','xxx');
define('BITLY_API_KEY','xxx');
function curl($url, $params) {
$params_str = http_build_query($params);
$curl = curl_init();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POST,count($params));
curl_setopt($curl, CURLOPT_POSTFIELDS,urlencode($params_str));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$rs = curl_exec($curl);
curl_close($curl);
return $rs;
}
$access_token = curl('https://api-ssl.bitly.com/oauth/access_token',array('client_id'=>BITLY_CLIENT_ID,'client_secret'=>BITLY_CLIENT_SECRET,'x_auth_username'=>'MY_USERNAME','x_auth_password'=>'MY_PASSWORD'));
echo $access_token;exit; // Returns INVALID_CLIENT_ID