2011-12-04 52 views
0

我要準確地告訴我的作業:爲網站添加Twitter搜索功能。搜索應每20秒自動更新一次,並搜索最近提到的散列標籤'#EN0700'。使用Twitter搜索API的位置和OAuth問題

推文應顯示在列表中,其中包含日期,作者在Twitter上的用戶名以及推文位置數據(推文被推送的位置)。我試圖在http://dev.twitter.com/docs/api/1/get/geo/search示例中使用https://api.twitter.com/1/geo/search.json?query=Twitter%20HQ,但它不顯示位置結果。我的網址是否正確?

的另一件事是,如果我使用http://api.twitter.com/1/users/search.json?q=Twitter%20API,我收到:

"{"error":"Could not authenticate you.","request":"/1/users/search.json?q=EN0745"}" 

雖然我已經註冊了我在OAuth應用。謝謝您的幫助。

回答

0

你可以用我的同班同學簽字請求https://github.com/andreyknupp/Twitter

<?php 
     spl_autoload_register (function ($class) { 
      require_once sprintf ('%s.php' , $class) ; 
     }) ; 

     $URL = 'https://api.twitter.com/1/users/search.json'; 
     $Data = Array ('q' => 'Search') ; 

     $Authentication = new \Twitter\TwitterAuthentication(); 

     $Authentication->setConsumerKey ('UExmB6GoxftjZqdngw'); 
     $Authentication->setConsumerSecret ('1yUvMAnrFiu86vCdhwAqM5ZHsgXRVyNhRdUDxeo'); 
     $Authentication->setAccessToken ('2660353-PjccZS0nO28zaV0xaxR2UBklZR0nkjjso2wmLa'); 
     $Authentication->setAccessTokenSecret ('DWwLG3RFt1drU0qRc4PHu0wdlmVks08BDM'); 

     $OAuth = new Twitter\TwitterOAuthentication($Authentication); 
     $OAuth->setSignatureURL ($URL . '?' . http_build_query ($Data , false , '&')) ; 
     $OAuth->setSignatureMethod('GET') ; 

     $curl = curl_init(); 
     curl_setopt($curl , CURLOPT_URL , $URL . '?' . http_build_query ($Data , false , '&')) ; 
     curl_setopt($curl , CURLOPT_HEADER , false) ; 
     curl_setopt($curl , CURLOPT_HTTPHEADER , Array ($OAuth->buildAuthorization($Data))) ; 
     curl_setopt($curl , CURLOPT_RETURNTRANSFER , true) ; 
     curl_setopt($curl , CURLOPT_SSL_VERIFYPEER , false); 

     $response = json_decode (curl_exec ($curl)) ; 
     print_r ($response) ;