Friday, December 25, 2009

A Simple Twitter Logger

[UPDATE! Look here for the OAuth version.]



Yes, using The Object Guy's Logging Framework it is incredibly easy to create a logger that will write to Twitter.

Here's a sample:

public class TwitterLogger : Logger
{  
  protected override bool DoLog(LogEntry aLogEntry)
  {
    // without this, you may receive a '417 Expectation Failed' error
    ServicePointManager.Expect100Continue = false;

    using (WebClient webClient = new WebClient())
    {
       webClient.Credentials = new NetworkCredential("[YOUR USER NAME]", "[YOUR PASSWORD]");

       var nvc = new NameValueCollection();
       nvc["status"] = aLogEntry.Message;

       webClient.UploadValues("http://twitter.com/statuses/update.xml", nvc);
    }
    return true;
  }
}

Remember that Twitter may limit your status updates to 150 per hour and a thousand or so per day.

18 comments:

  1. Hey, that's neat.

    ReplyDelete
    Replies
    1. Machine Learning Projects for Final Year machine learning projects for final year

      Deep Learning Projects assist final year students with improving your applied Deep Learning skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include Deep Learning projects for final year into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Deep Learning Projects for Final Year even arrange a more significant compensation.

      Python Training in Chennai Project Centers in Chennai

      Delete
  2. I'm getting a 417 exception failed errorat WebClient.UpladValues(Uri address, String method, NameValueCollection data)

    Do you know any fixes?

    ReplyDelete
  3. Look carefully at the code I posted. You'll see that I address the 417 error.

    ReplyDelete
  4. Sorry about that, I totally missed it. Now I'm getting a 403 Forbidden error. Do you know what could be causing that?

    ReplyDelete
  5. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. smm panel

    ReplyDelete
  6. Nice & Informative Blog! I would like to say thank you for the efforts you had made for writing this awesome article. This article inspired me to read more your blogs. keep it up. Visit SMM Panel for any kind of Social Media Marketing Services.

    ReplyDelete
  7. Wow! what a Great Information. This is very nice one and gives indepth information. Thanks for sharing such a wonderful article. Visit SMM Panel for any kind of SMM Services.

    ReplyDelete
  8. Wow! Really an amazing article. I am very much pleased with the contents you have shared. Thanks for sharing such a valuable information. Keep up your good work. Visit cheapest smm panel for any kind of SMM Services.

    ReplyDelete
  9. Thanks for sharing a lot of information. This article inspired me to read more your blogs. keep it up. Visit buy ig like for any kind of Social Media Marketing Services.

    ReplyDelete
  10. This post is very useful info. This is my first time I visit here. I have found so much interesting stuff in your blog especially its discussion. Thanks for sharing such a wonderful article. Keep up your good work. Visit the smm providers for any kind of SMM Services.

    ReplyDelete
  11. Hi, Your Article very Informative and Helpful. Thank you very much.
    smm panel
    SEO Consultant
    https://peakerr.com

    ReplyDelete
  12. Hi, Your Article very Informative and Helpful. Thank you very much.
    smm services
    SEO Consultant
    https://peakerr.com

    ReplyDelete
  13. Top 10 best slots casinos for 2021 - SOL.EU
    Best Slots Casino: Best Real Money Slots Sites titanium ring 2021 ventureberg.com/ · Red Dog Casino: Best Overall https://sol.edu.kg/ Slots Casino For USA 바카라 사이트 Players · Ignition Casino: Best 1xbet login Casino For Roulette

    ReplyDelete
  14. Name: instagram panel
    https://peakerr.com/
    Hello, I read Your Article. This is very Helpful for me. Thanks. Please try
    instagram panel

    ReplyDelete
  15. Hello, I read Your Article. This is very Helpful for me. Thanks. Please try
    instagram panel

    ReplyDelete
  16. instagram panel
    https://peakerr.com/
    Hello, I read Your Article. This is very Helpful for me. Thanks. Please try
    instagram panel

    ReplyDelete