Code 30.07.2009, 00:00 Uhr

Code des Mini-Twitter-Frontends Twitty

In wenigen Minuten exklusiv für Sie zusammengezimmert: Der Code für das Posten von Nachrichten in Twitter.
Den Code muss man mit einigen Attributen verzieren:

- quick and dirty
- keineswegs Clean Code
- Zugangsdaten zu Twitter sind nicht gesichert
- aber wie so oft: er funktioniert

Er verwendet Linq 2 Twitter http://linqtotwitter.codeplex.com/.
Twitter Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LinqToTwitter;

namespace Twitty
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      toolStripStatusLabel1.Text = "Working ...";
      toolStripStatusLabel1.BackColor = Color.Orange;
      this.Refresh();

      string userName = Twitty.Properties.Settings.Default.userName;
      string password = Twitty.Properties.Settings.Default.password;

      try
      {
        // For Twitter
        var twitterCtx = new TwitterContext(userName, password,
                "http://www.twitter.com/", "http://search.twitter.com/");
        var tweety = twitterCtx.UpdateStatus(textBox1.Text);
        toolStripStatusLabel1.Text = "Tweet with ID " + tweety.ID + " posted";
        toolStripStatusLabel1.BackColor = Color.Green;
      }
      catch (Exception ex)
      {
        toolStripStatusLabel1.Text = ex.Message;
        toolStripStatusLabel1.BackColor = Color.Red;
      }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      Left = Screen.PrimaryScreen.Bounds.Width - Width;
    }
  }
}


Das könnte Sie auch interessieren