|
Forums » .NET » ASP.NET »
|
Display tweets from twitter |
Posted Date: 04 Jul 2011 Posted By:: chirag Member Level: Silver Member Rank: 971 Points: 2
Responses:
13
|
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
Chirag - 48 Enjoy With Errors chirag.madhani@yahoo.com
|
Responses
|
#618236 Author: Rajdev Member Level: Silver Member Rank: 358 Date: 04/Jul/2011 Rating:  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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Twitter Search</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblHTMLOutput" runat="server"></asp:Label> </div> </form> </body> </html>
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 + "<br>" 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.
Twitterizer2-2.3.2.zip | #618240 Author: chirag Member Level: Silver Member Rank: 971 Date: 04/Jul/2011 Rating:  Points: 1 | thnx....
but do u have this application in c#..
if have then response me as its urgent..
Chirag - 48 Enjoy With Errors chirag.madhani@yahoo.com
| #618251 Author: Rajdev Member Level: Silver Member Rank: 358 Date: 04/Jul/2011 Rating:  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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Twitter Search</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblHTMLOutput" runat="server"></asp:Label> </div> </form> </body> </html>
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<TwitterSearchResultCollection> 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 + "<br>"; 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.
| #618261 Author: chirag Member Level: Silver Member Rank: 971 Date: 04/Jul/2011 Rating:  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
Chirag - 48 Enjoy With Errors chirag.madhani@yahoo.com
| #618262 Author: Rajdev Member Level: Silver Member Rank: 358 Date: 04/Jul/2011 Rating:  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?
| #618504 Author: chirag Member Level: Silver Member Rank: 971 Date: 05/Jul/2011 Rating:  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....
Chirag - 48 Enjoy With Errors chirag.madhani@yahoo.com
| #618522 Author: Rajdev Member Level: Silver Member Rank: 358 Date: 05/Jul/2011 Rating:  Points: 1 | Hi,
Hope this helps you:
http://www.codeproject.com/KB/aspnet/TweetsInAspNet.aspx
| #618533 Author: chirag Member Level: Silver Member Rank: 971 Date: 05/Jul/2011 Rating:  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..
Chirag - 48 Enjoy With Errors chirag.madhani@yahoo.com
| #618587 Author: Rajdev Member Level: Silver Member Rank: 358 Date: 06/Jul/2011 Rating:  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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Twitter Search</title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server">
</asp:GridView> </form> </body> </html>
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.
| #618639 Author: chirag Member Level: Silver Member Rank: 971 Date: 06/Jul/2011 Rating:  Points: 1 | thanx...
it sove my many problems...
u have really help meso much
thanx thanx alot..
Chirag - 48 Enjoy With Errors chirag.madhani@yahoo.com
| #656774 Author: MdSaleha Member Level: Bronze Member Rank: 0 Date: 11/Feb/2012 Rating:  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
| #656967 Author: vijayalakshmi Member Level: Bronze Member Rank: 0 Date: 13/Feb/2012 Rating:  Points: 2 | Plz sir I need answer…………….but that code output is no response……..just display on labe on local host
rply.docx |
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|