jQueryを使用して、ハッシュタグを含むツイートを取得および表示します

StackOverflow https://stackoverflow.com/questions/5324791

  •  25-10-2019
  •  | 
  •  

質問

$ _GETメソッドを介して、前のページのドロップダウンリストから2つのハッシュタグ変数(サッカーチーム)を受け取ります。これらは、チーム1に関する最新のツイートを表示するために操作しようとしているJavaScript変数に保存されます。

Twitter検索URLの構築またはツイートを取得する関数自体($ .getJson(url、function(tweet))のいずれかで苦労しているようです。とにかく、コードは以下です。ありがとう。ありがとう見てください。

 <div id="mainContent">
 <script type="text/javascript"> 
 var team1, team2; 
 team1 = '<?php echo $_GET["team1"]; ?>'; 
 team2 = '<?php echo $_GET["team2"]; ?>'; 
 </script>

<div id="last-tweet">
</div>

<script type="text/javascript">
$(document).ready(function(){
var format='json'; // set format
var url='http://search.twitter.com/search.json?q=%23' + team1 + '&callback=?';
$.getJSON(url,function(results){ // get the tweets
$("#last-tweet").html(results[0].text); // get the first tweet in the response and place it inside the div
});
});

更新:それ以来、返されるJSONファイルをチェックアウトしましたが、おそらくデータを参照するために使用しているキーワードは、「ツイート」ではなく「結果」であるように思われます(例:結果[0])。しかし、私はこれのためにastjustmentsを作りましたが、それでも運はありません。 FireBugは、「結果は未定義です」と報告しています。

JSONファイルのスニペットは次のとおりです。

{"results":[{"from_user_id_str":"118766757","profile_image_url":"http://a0.twimg.com/profile_images/1128884063/ManchesterUnited07_normal.jpg","created_at":"Thu, 17 Mar 2011 11:02:21 +0000","from_user":"sarthak_dev90","id_str":"48338376365056000","metadata":{"result_type":"recent"},"to_user_id":null,"text":"#ificouldiwouldbringback Tevez to #MUFC. He made a difference almost every time he played.", 
役に立ちましたか?

解決

ブラウザから以下のURLにアクセスしてください http://search.twitter.com/search.json?q = liverpool 出力JSONをファイルに保存してから、JSONの形式を分析します。

たとえば、JSON出力がある場合

{"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
};

あなたの 'ツイート[0] .text'はに変換する必要があります

bindings[0].method    // will output "newURI"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top