Twittr上的REST API调用

来源:互联网 发布:如何装修淘宝店铺视频 编辑:程序博客网 时间:2024/05/17 23:02
隐藏行号 复制代码 code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.ServiceModel.Syndication;
  10. using System.Xml;
  11. namespace TwitterAnalysis
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             listView1.Items.Clear();
  22.             int pagenum = 1;
  23.             while (true)
  24.             {
  25.                 string url = "http://search.twitter.com/search.atom?q=" + textBox3.Text + "&rpp=100&page=" + pagenum + "&show_user=true";
  26.                 SyndicationFeed feed = SyndicationFeed.Load(XmlReader.Create(url));
  27.                 var items = from item in feed.Items
  28.                             orderby item.PublishDate descending
  29.                             select new { Author = item.Authors[0].Name, Date = item.PublishDate.Date., Content = item.Title.Text };
  30.                 int count = 0;
  31.                 foreach (var item in items)
  32.                 {
  33.                     ListViewItem i = new ListViewItem(item.Author);
  34.                     i.SubItems.Add(item.Date);
  35.                     i.SubItems.Add(item.Content);
  36.                     listView1.Items.Add(i);
  37.                     count++;
  38.                 }
  39.                 if (count < 100)
  40.                     break;
  41.                 else
  42.                     pagenum++;
  43.             }
  44.         }
  45.     }
  46. }
.src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px}.src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px}.src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden}.toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;}.src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif}.src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important}.number_show{ padding-left:52px !important; list-style:decimal outside !important}.number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd}.number_hide{ padding-left:0px !important; list-style-type:none !important}.number_hide li{ list-style-type:none !important; border-left:0px}ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd}ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}.linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word}ol.mainarea li pre.alt{ background-color:#f7f7ff !important}
原创粉丝点击