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


  • […] This is the same functionality I demo’d in C# in my first post. […]

    11/08/2011
  • Clement

    any pointers on how to add it to the web config file? I’m stuck on the section name and type

    03/07/2012
    • 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.

      03/07/2012
  • Clement

    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 :(

    03/08/2012
  • Clement

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

    03/08/2012
  • Sounds good. Let me know if you’re getting a specific error. If it helps, here is the Twitterizer test cases that helped me get through some initial problems:
    http://svn.twitterizer.net/twitterizer/trunk/Twitterizer2.TestCases/TwitterListTests.cs

    03/08/2012
  • Clement

    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.

    03/14/2012
  • Clement

    Is there meant to be a way of identifying what user timeline I’m trying to display?

    03/19/2012

Leave a comment


Name*

Email(will not be published)*

Website

Your comment*

Submit Comment

© Copyright Duke Hall - Designed by Pexeto