Twitterizer & .Net: Adding a feed to your website

Create a Twitter user:
http://twitter.com/

Register your application:
https://dev.twitter.com/apps/new
This gives you:
    <add key=”AccessToken” value=”blahblahblah”/>
    <add key=”AccessTokenSecret” value=”blahblahblah”/>
    <add key=”ConsumerKey” value=”blahblahblah”/>
    <add key=”ConsumerSecret” value=”blahblahblah”/>
Add it to your web.config

Go to:
http://www.twitterizer.net/downloads/
Download the Twitterizer package:
Twitterizer2-2.3.2.zip.

Add
Twitterizer2.dll and Newtonsoft.Json.dll
in your project references

Make an ASPX page with:
                    <div id=”homeDev”>
                        <fieldset style=”width: 230px”>
                            <legend>Development Buzz</legend>
                            <%=Data1%>
                        </fieldset>
                    </div>

Do this in the .CS
 public partial class Home : System.Web.UI.Page
    {
        private string _data1;
        public string Data1
        {
            get { return _data1; }
            set { _data1 = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ConnectTwitter();
        }

        protected void ConnectTwitter()
        {
            OAuthTokens tokens = new OAuthTokens();
            tokens.AccessToken = ConfigurationManager.AppSettings[“AccessToken”];
            tokens.AccessTokenSecret = ConfigurationManager.AppSettings[“AccessTokenSecret”];
            tokens.ConsumerKey = ConfigurationManager.AppSettings[“ConsumerKey”];
            tokens.ConsumerSecret = ConfigurationManager.AppSettings[“ConsumerSecret”];
           
            TwitterResponse<TwitterStatusCollection> statuses = TwitterTimeline.HomeTimeline(tokens);
            for (int i = 0; i < statuses.ResponseObject.Count; i++)
            {
                Data1 += “<p>”;
                Data1 += statuses.ResponseObject[i].Text.ToString();
                Data1 += “</p>”;
            }
        }
    }

8 comments on “Twitterizer & .Net: Adding a feed to your website

  1. Pingback: Intro to SQL # For Twitterizer | Mike Duke Hall's .Net blog

    • Hey Clement,

      I usually put application specific key/value pairs in the appsettings section of the web.config. So, it would go something like this:

      <appSettings>
          <add key=”AccessToken” value=”blahblahblah”/>
          <add key=”AccessTokenSecret” value=”blahblahblah”/>
          <add key=”ConsumerKey” value=”blahblahblah”/>
          <add key=”ConsumerSecret” value=”blahblahblah”/>
      </appSettings>
      

      Let me know if that works for you.

  2. That works thanks, but I’ve got an issue referencing my ConfigurationManager. The keys are stored in ACMSettings.config (we’re using Alterian) which is referenced in the web.config file as .
    Do you know what I can use to replace ConfigurationManager with in the cs file? It’s currently underlined in red 😦

  3. fixed it, forgot to add using System.Configuration – only problem now is using the protected void ConnectTwitter() but I’m getting there.
    🙂

  4. I’ve still got a problem connecting, what access do I give the app in my Twitter account? It says connected host failed to respond in a timely manner.

Leave a comment