本文整理汇总了C#中Twitter.GetTweets方法的典型用法代码示例。如果您正苦于以下问题:C# Twitter.GetTweets方法的具体用法?C# Twitter.GetTweets怎么用?C# Twitter.GetTweets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twitter
的用法示例。
在下文中一共展示了Twitter.GetTweets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
Uri tokenUri = new Uri("https://api.twitter.com/oauth2/token");
Uri userTimelineUri = new Uri("https://api.twitter.com/1.1/statuses/user_timeline.json");
var twitter = new Twitter();
var credential = new BearerTokenCredential(ConsumerKey, ConsumerSecret);
var tokenRequest = new BearerTokenRequest(credential, tokenUri);
IBearerToken token= twitter.RequestBearerToken(tokenRequest);
Console.WriteLine(token);
string screenName = "JohnRentoul";
var tweetsRequest = new TweetRequest(token, userTimelineUri, screenName);
var tweets = twitter.GetTweets(tweetsRequest);
Console.WriteLine();
Console.WriteLine("--------");
Console.WriteLine();
List<SyndicationItem> items = new List<SyndicationItem>();
int counter = 0;
foreach (var tweet in tweets)
{
if (tweet.ContainsLinks)
{
counter++;
foreach (var link in tweet.Links)
{
Console.WriteLine(link.AbsoluteUri);
}
StringBuilder content = new StringBuilder();
content.AppendLine(tweet.text);
foreach(var link in tweet.Links)
{
string linkTag = string.Format(@"<a href='{0}'>{0}</>", link.AbsoluteUri);
content.AppendLine(linkTag);
}
SyndicationItem item = new SyndicationItem(screenName + counter, content.ToString(), new Uri("http://localhost"));
items.Add(item);
}
}
var syndicationFeed = new SyndicationFeed("LinkTwrapper", "Tweets containing links", new Uri("http://localhost"))
{ Items = items };
string timestamp = DateTime.Now.ToString("yyyy-MM-dd_hhmmssfff");
string filePath = string.Format(@"C:\WS\LinkTwrapper\RSSFiles\Tweets{0}.rss", timestamp);
using (var fileStream = File.Create(filePath))
{
using (var xmlWriter = XmlWriter.Create(fileStream))
{
syndicationFeed.SaveAsRss20(xmlWriter);
xmlWriter.Flush();
}
}
Console.ReadLine();
}