2012-03-14 14 views
0

自分のデータベースにツイートをダウンロードしたいです。スクリプトに#subjectをつけて、最新のつぶやきをダウンロードしたいと思います。私はPHPでこれをしたいツイートから位置情報を保存

私はあなたがそれを監視することができますが、私はスクリプトが必要なウェブサイトを見つけることができます。誰か知っていますか?

重要なのは、メッセージ、作成者、および場所をダウンロードできることです。 私はtwitterに慣れていないので、これが可能かどうかわかりません。

おかげで、

トビー

+1

"スクリプトに#subjectを付けたい"。あなたはあなたが与えたキーワードに応じて質問を出し、結果を得たいと思っていますか? – Zakaria

答えて

1

これは、RESTfulなWebサービスとして実装されてTwitter APIを使用して伴うだろう。主にあなたはTwitter search APIを使用しています。 TwitterのAPIを使用して

とAPIを検索:あなたはすでにそれが、その後search pageを使用するかわからない場合は、必要 最初の事は、検索クエリです。検索URLの末尾に、検索APIのパラメータとして使用します。たとえば、ハッシュタグ#stackoverflowを検索すると、次のURLが表示されます。

http://twitter.com/#!/search/%23stackoverflow 

検索APIのクエリは次のようになります。

http://search.twitter.com/search.json?q=%23stackoverflow 

上記のURLは、PHPスクリプトで解析して使用できるJSONレスポンスを返します。

はPHPで検索を解析:TwitterのAPIでこのスクリプトインターフェースは 、結果を出力し、読者に左結果を記憶する運動である。

<?php 
class Twitter { 
    public function __construct() { } 
    public function searchResults($query = null) { 
     $url = "http://search.twitter.com/search.json?q=" . urlencode($query); 
     $curl = curl_init(); 

     // cURL options for the current session. 
     $options = array(CURLOPT_URL => $url, 
         CURLOPT_RETURNTRANSFER => 1 
        ); 
     // If all the options are set correctly then fetch and parse the results. 
      if (curl_setopt_array($curl, $options)) { 
       // Execute cURL and store the returned string. 
       $json_search_results = curl_exec($curl); 
       curl_close($curl); 
       // Decode the JSON string returned by cURL. 
       $search_results = json_decode($json_search_results); 
       return $search_results; 
      } 
    } 
} 

// Searching Twittter using the new class. 
$Twitter = new Twitter(); 
$search = Twitter::searchResults("#stackoverflow"); 
var_dump($search); 
?> 

スクリプトの出力:

object(stdClass)#2 (11) { 
    ["completed_in"]=> 
    float(0.137) 
    ["max_id"]=> 
    int(179961163788976129) 
    ["max_id_str"]=> 
    string(18) "179961163788976129" 
    ["next_page"]=> 
    string(52) "?page=2&max_id=179961163788976129&q=%23stackoverflow" 
    ["page"]=> 
    int(1) 
    ["query"]=> 
    string(16) "%23stackoverflow" 
    ["refresh_url"]=> 
    string(47) "?since_id=179961163788976129&q=%23stackoverflow" 
    ["results"]=> 
    array(15) { 
    [0]=> 
    object(stdClass)#3 (18) { 
     ["created_at"]=> 
     string(31) "Wed, 14 Mar 2012 16:04:19 +0000" 
     ["from_user"]=> 
     string(7) "kel666_" 
     ["from_user_id"]=> 
     int(55252171) 
     ["from_user_id_str"]=> 
     string(8) "55252171" 
     ["from_user_name"]=> 
     string(14) "Fabio Spinelli" 
     ["geo"]=> 
     NULL 
     ["id"]=> 
     int(179961163788976129) 
     ["id_str"]=> 
     string(18) "179961163788976129" 
     ["iso_language_code"]=> 
     string(2) "it" 
     ["metadata"]=> 
     object(stdClass)#4 (1) { 
     ["result_type"]=> 
     string(6) "recent" 
     } 
     ["profile_image_url"]=> 
     string(71) "http://a0.twimg.com/profile_images/585239857/n571218917_3111_normal.jpg" 
     ["profile_image_url_https"]=> 
     string(73) "https://si0.twimg.com/profile_images/585239857/n571218917_3111_normal.jpg" 
     ["source"]=> 
     string(59) "&lt;a href=&quot;http://twitter.com/&quot;&gt;web&lt;/a&gt;" 
     ["text"]=> 
     string(114) "postare domande su #stackoverflow è fico perché c'è sempre pronto qualcuno a cazziarti o cmq a far la maestrina" 
     ["to_user"]=> 
     NULL 
     ["to_user_id"]=> 
     NULL 
     ["to_user_id_str"]=> 
     NULL 
     ["to_user_name"]=> 
     NULL 
    } 
    // Snip. 
    ["results_per_page"]=> 
    int(15) 
    ["since_id"]=> 
    int(0) 
    ["since_id_str"]=> 
    string(1) "0" 
} 
+0

ありがとう、私はこれを探していた –

関連する問題