Click here to Skip to main content
15,890,506 members
Articles / Programming Languages / C#
Tip/Trick

WebMonster

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Oct 2012CPOL1 min read 8.5K   2  
The code shown here allows a user to get all public tweets of her /his liking without logging into Twitter and search for tweets with keywords. It also allows the user to search for his/her friends who are tagged in his/her albums.

Introduction

The code shown here allows a user to get all public tweets of her /his liking without logging into Twitter and search for tweets with keywords. It also allows the user to search for his/her friends who are tagged in his/her albums.

Using the code

The code uses Twitter API and Facebook API.

Whenever a user enters the name then it is added to Screen_Name. E.g.: If I enter Ravi then the link will look at getting all public tweets made by the user (we can get only the top 200 tweets (public)).

We are using the asynch features of .NET 4.5 so the application will not hang during the download and the user can download pictures from Facebook and search for friends who are tagged in Facebook and can also share their pics which are locally stored.

After successful download of the tweets the user can download and search the tweets with any keyword.

C#
//The Following Code will Download the Tweets
private async void gettweets_Tapped(object sender, TappedRoutedEventArgs e) {
//We used Tapped event so that application can sense touch event as well.
Windows.Web.Syndication.SyndicationClient client = new Windows.Web.Syndication.SyndicationClient();
// Force the SyndicationClient to download the information.
client.BypassCacheOnRetrieve = true;
Uri feedUri = new Uri("http://api.twitter.com/1/statuses/user_timeline." + 
    "JSON?count=200&screen_name=XXXXXXX",UriKind.RelativeOrAbsolute);
try {
    // Call SyndicationClient RetrieveFeedAsync to download the list of blog posts.
    Windows.Web.Syndication.SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri); 
    // The rest of this method executes after await RetrieveFeedAsync completes. 
    Tweets.Text = feed.Title.Text + Environment.NewLine; 
    foreach (SyndicationItem item in feed.Items) 
    {
        Tweets.Text += item.Title.Text + ", " + 
               item.PublishedDate.ToString() + Environment.NewLine; 
    }
} 
catch (Exception ex) { 
    // Log Error. 
    Tweets.Text = "I'm sorry, but I couldn't load the page," + 
      " possibly due to network problems." + 
      "Here's the error message I received: " + ex.ToString();
}

The following code will search for a keyword within the public tweets:

C#
var subset = from g in textbx1.Text where g.Contains(searchTb.Text) select g;
foreach (var stat in subset)
{
    richTextBox1.Text += stat + "\n" + 
      "_________________________________________________________" + "\n";
}

Similarly we use the Facebook API and download pictures from albums and share them if they are locally available.

Users can see all public tweets without logging into Twitter and can search for friends who are tagged in their albums.

Points of interest

Here we are using the Tap event in order to make the application completely use the touch features of the Intel Ultrabook. We used the Twitter API and FaceBook API along with C# 4.5 and XAML. We can also download the tweets in XML format.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --