【问题标题】:Location and OAuth problems using Twitter search API使用 Twitter 搜索 API 的位置和 OAuth 问题
【发布时间】:2012-01-12 17:26:59
【问题描述】:

我将准确地讲述我的作业:为网站添加 twitter 搜索功能。搜索应每 20 秒自动更新一次,并搜索最近提及的哈希标签“#EN0700”。

推文应显示在一个列表中,其中包含日期、推特上作者的用户名和推文位置数据(推文发布的位置)。我尝试像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 中注册了我的应用程序。感谢您的帮助。

【问题讨论】:

    标签: php twitter twitter-oauth


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您最好使用 PHP 库来简化操作。你可以找到他们here on the Twitter Developers site.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-30
        • 2012-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-26
        相关资源
        最近更新 更多