You must Sign In to post a response.
  • Category: ASP.NET

    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
  • #618236
    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

    Delete Attachment

  • #618240
    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
    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
    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
    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
    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
    Hi,

    Hope this helps you:

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

  • #618533
    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
    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
    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
    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

  • #656963
    Plz Send Exact Code

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

    rply.docx

    Delete Attachment


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.