You must Sign In to post a response.

Display tweets from twitter

Create a web application to display 10 most relevant tweets from Twitter in real-time for the keyword "@cldmgc".

Do any one have any idea about it or how to start with it.??

Thanks


Comments

Author: Rajdev04 Jul 2011 Member Level: Silver   Points : 4

Hi,

There is a website called: http://www.twitterizer.net which contains dll for twitter. I have created a sample using it. Its working fine as per your requirement.

Step 1: Download Twitterizer2-2.3.2.zip from the link http://www.twitterizer.net/downloads/#latest
Step 2: Extract the zip file, add reference of Twitterizer2.dll into the project
Step 3: Create a webpage with a label
Step 4: Import Twitterizer namespace which contains all the classes related to twitter
Step 5: Set the search stirng(@cldmgc) and search using TwitterSearch.Search() method
Step 6: Loop through the result and display as you required. Also have a counter to display first 10 records

Here is the working sample:

SearchTwitter.Aspx:
--------------------



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SearchTwitter.aspx.vb" Inherits="SearchTwitter" %>





Twitter Search











SearchTwitter.aspx.vb
-----------------------




Imports Twitterizer

Partial Class SearchTwitter
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' String to Search
Dim query As String = "@cldmgc"
Dim recCount As Integer = 1

' Get the search result
Dim searchResult As TwitterResponse(Of TwitterSearchResultCollection) = TwitterSearch.Search(query)

' Loop the search result to display them
For Each tweet As TwitterSearchResult In searchResult.ResponseObject
If recCount <= 10 Then
lblHTMLOutput.Text = lblHTMLOutput.Text + tweet.CreatedDate.ToString() + " " + tweet.FromUserScreenName + " " + tweet.Text + "
"
recCount = recCount + 1
Else
Exit For
End If
Next

End Sub
End Class


I have also attached the zip file I have mentioned. Please use it if you are not able to find it in the link given.

Please post whether this solves your issue, or still facing any.

Author: chirag04 Jul 2011 Member Level: Silver   Points : 1

thnx....

but do u have this application in c#..

if have then response me as its urgent..

Author: Rajdev04 Jul 2011 Member Level: Silver   Points : 4

You could have used http://www.developerfusion.com/tools/convert/vb-to-csharp/ to convert vb.net to c# or vice versa.

Anyhow, here is the c# version of the vb.net code in my earlier reply. Its tested and working fine.

SearchTwitterCS.aspx
-----------------------



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SearchTwitterCS.aspx.cs" Inherits="SearchTwitterCS" %>





Twitter Search











SearchTwitterCS.aspx.cs
-------------------------


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Twitterizer;

public partial class SearchTwitterCS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// String to Search

string query = "@cldmgc";
int recCount = 1;

// Get the search result
TwitterResponse searchResult = TwitterSearch.Search(query);

// Loop the search result to display them
foreach (TwitterSearchResult tweet in searchResult.ResponseObject)
{
if (recCount <= 10)
{
lblHTMLOutput.Text = lblHTMLOutput.Text + tweet.CreatedDate.ToString() + " " + tweet.FromUserScreenName + " " + tweet.Text + "
";
recCount = recCount + 1;
}
else
{
break; // TODO: might not be correct. Was : Exit For
}
}
}
}


Make use of the zip file attached with previous reply, if you are not able to download it from the given link.

Please post whether this solves your issue, or still facing any.

Author: chirag04 Jul 2011 Member Level: Silver   Points : 1

Hey thanx rajan its excellent...

bt where is user name and password option means if i want to enter user name and password then how to do.??

and in this code whose tweets r there ..how can we come to know?

thanx

Author: Rajdev04 Jul 2011 Member Level: Silver   Points : 2

This code doesn't require username and password.

Let's take a look at the first result:


04-07-2011 11:55:37 franlacas Instant search for your online data http://t.co/GxiPPrj vía @cldmgc


It contains three parts:

1. 04-07-2011 11:55:37 - Create date time of the tweet
2. franlacas - The user who created this tweet
3. Instant search for your online data http://t.co/GxiPPrj vía @cldmgc - Actual text of the tweet

Does these information sufficient enough for your requirement or you need more?

Author: chirag05 Jul 2011 Member Level: Silver   Points : 1

this code might not require username $ password but i need to display of tweets of particular username and password

so i m confused that how can i get username $ password to tweets

i am sending u defination so it might clear to u

Create a web application to display 10 most relevant tweets from Twitter in real-time for the keyword "@cldmgc".

if possible than u please help its really urgent..

Thanx....

Author: Rajdev05 Jul 2011 Member Level: Silver   Points : 1

Hi,

Hope this helps you:

http://www.codeproject.com/KB/aspnet/TweetsInAspNet.aspx

Author: chirag05 Jul 2011 Member Level: Silver   Points : 1

but it is in vb.net and i want in asp.net C#..

and tommorow means wed evening is last day for submission so its really urgent..

thanx..

Author: Rajdev06 Jul 2011 Member Level: Silver   Points : 1

Hi,

Am afraid that I am not able to help you exactly since am not a Tweeter!!

I have modified the code to c# and it does produce some results. Please check whether this is useful for you.

ASPX:
------


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SearchUsersTwitterCS.aspx.cs" Inherits="SearchUsersTwitterCS" %>





Twitter Search











ASPX.CS:
--------


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Twitterizer;
using System.Xml;
using System.Net;

public partial class SearchUsersTwitterCS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = null;
string twitterUrl = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=nereolopez";
WebClient client = new WebClient();
str = client.DownloadString(twitterUrl);

XmlDocument myXml = new XmlDocument();
myXml.LoadXml(str);

DataSet ds = new DataSet();
ds.ReadXml(new XmlNodeReader(myXml));

DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns.Add("Time");
dt.Columns.Add("Link");

DataRow row = null;
if (ds.Tables["status"] != null && ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i <= ds.Tables["status"].Rows.Count - 1; i++)
{
row = dt.NewRow();
row["Title"] = ds.Tables["status"].Rows[i][2].ToString();
row["Time"] = ds.Tables["status"].Rows[i][0].ToString();
string lnk = "http://twitter.com/" + ds.Tables["user"].Rows[i][2].ToString() + "/statuses/";
row["Link"] = lnk + ds.Tables["status"].Rows[i][1].ToString();
dt.Rows.Add(row);
}
}

GridView1.DataSource = dt;
GridView1.DataBind();
dt.Dispose();

}
}




Here, "nereolopez" is the twitter name.

Author: chirag06 Jul 2011 Member Level: Silver   Points : 1

thanx...

it sove my many problems...

u have really help meso much

thanx thanx alot..

Author: MdSaleha11 Feb 2012 Member Level: Bronze   Points : 1

hay chirag ...did u get response by submitting this application..
becoz i too have got same mail..with same question...and pls let me know the procedure to run this application...pls it ill be a favour,pls reply fast...i need to subit two days after so pls..
thanks
md saleha

Author: vijayalakshmi13 Feb 2012 Member Level: Bronze   Points : 0

Plz Send Exact Code

Author: vijayalakshmi13 Feb 2012 Member Level: Bronze   Points : 2

Plz sir I need answer…………….but that code output is no response……..just display on labe on local host


Sign In to post your comments