2012-05-25 2 views
0

모든 Twitter 요청에 대해 the returned HTTP headers should include X-RateLimit-Limit을 작성하십시오.PHP에서 Twitter의 X-RateLimit 제한을 검색하십시오.

그러나 PHP를 사용하여 검색 할 수없는 것 같습니다. 누군가 내가 뼈를 자른 실수가 무엇인지 말해 줄 수 있습니까?

정상적인 방법으로 컬을 설정했으며 GET 및 POST 요청을 성공적으로 수행 할 수 있습니다.

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_HEADER, FALSE); 
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); 
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); 

$response = curl_exec($ch); 
$response_info=curl_getinfo($ch); 
$erno = curl_errno($ch); 
$er = curl_error($ch); 
curl_close($ch); 

나는 HTTP_CODE

$response_info['http_code'] 

같은 일부 응답 정보를 얻을 수 있어요하지만이 라인은 그냥 PHP 버전 5.3.10을 실행하는거야

//Doesn't bloody work. No idea why! 
$rate_limit = $response_info['X-RateLimit-Limit']; 

null를 돌려줍니다.

EDIT

이것은 인 print_r ($의 response_info)의 결과이고;

Array 
(
[url] => https://api.twitter.com/1/statuses/home_timeline.json... 
[content_type] => application/json;charset=utf-8 
[http_code] => 200 
[header_size] => 695 
[request_size] => 410 
[filetime] => -1 
[ssl_verify_result] => 0 
[redirect_count] => 0 
[total_time] => 1.239977 
[namelookup_time] => 0.007361 
[connect_time] => 0.155783 
[pretransfer_time] => 0.465397 
[size_upload] => 0 
[size_download] => 99425 
[speed_download] => 80182 
[speed_upload] => 0 
[download_content_length] => 99425 
[upload_content_length] => 0 
[starttransfer_time] => 0.794829 
[redirect_time] => 0 
[certinfo] => Array() 
[redirect_url] => 
[request_header] => GET /1/statuses/home_timeline.json... HTTP/1.1 
Host: api.twitter.com 
Accept: */* 
) 
+0

당신이'위해서 var_dump ($의 response_info)를 사용하여 시도 가지고, 당신이 실제로 얻고있는 것을보고' 트위터에서? – Daan

+0

나는 X-RateLimit-Limit가 나타나지 않는다. –

+0

흠. [account/rate_limit_status] (https://dev.twitter.com/docs/api/1/get/account/rate_limit_status) 전화가 올바른 정보를 반환합니까? – Daan

답변

3

curl_getinfo 요청에 대한 다른 메타 정보 만 응답 헤더를 반환하지 않습니다. 헤더를 검색하려면 CURLOPT_HEADERtrue으로 설정하십시오. 출력에 헤더가 포함됩니다. 응답 본문에서 구분하기 위해 수행

list($headers, $body) = explode("\n\n", $response, 2); 

가 헤더를 구문 분석, 폭발 다시 :

$headers = explode("\n", $headers); 
foreach ($headers as $header) { 
    list($key, $value) = explode(':', $header, 2); 
    $headers[trim($key)] = trim($value); 
} 

echo $headers['X-RateLimit-Limit']; 
관련 문제