使用Twitter搜索API的位置和OAuth问题


Location and OAuth problems using Twitter search API

我要确切地告诉我的作业:在网站上添加twitter搜索功能。搜索应该每20秒自动更新一次,并搜索最近提到的"#EN0700"标签。

推文应该显示在一个列表中,包含日期、作者在twitter上的用户名和推文位置数据(推文发布的位置)。我尝试使用http://dev.twitter.com/docs/api/1/get/geo/search示例中的https://api.twitter.com/1/geo/search.json?query=Twitter%20HQ,但它不显示位置结果。我的URL是否正确?

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

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

虽然我已经在oAUTH注册了我的申请。谢谢你的帮助。

您可以使用我的类来签署请求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 ) ;

您可能最好使用PHP库来简化此操作。你可以在Twitter开发者网站上找到他们。