School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,475 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,757 people online right now. Registration is fast and FREE... Join Now!




X-Twitter

 

X-Twitter, Yet another Twitter application (but this one's better)

gabehabe

30 Sep, 2008 - 03:32 AM
Post #1

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
***UPDATE***
This program's coming along pretty quickly. I've set up a SourceForge at the following address:
https://sourceforge.net/projects/x-twitter/
If you want do download it for testing or just to use, I recommend you get it from there, because it will be the latest version.
Feedback is always welcome.
Enjoy!
***UPDATE***





This is a subject that's interested me for quite a while: Posting data to a site. I've done a bit of this already, so far I've got:

A function to grab the most recent 20 updates from any user
A function to post to your page
A login screen

I'm hoping to add extra features in to this too, stuff that isn't actually featured on Twitter. Stuff like "Top 5 Tweeters."

If you've got any thoughts/suggestions, I'd be glad to take them into consideration.

Oh yeah, it's in C#.NET (surprise, surprise) tongue.gif

I'll post it up as soon as I get a (basic) working version. smile.gif

User is online!Profile CardPM
+Quote Post


gabehabe

RE: X-Twitter

30 Sep, 2008 - 05:58 AM
Post #2

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
I've now added functions to get the most recent update, and get the user's display picture.

I'll be posting most of the news about this project on my Twitter through XTwitter, while I'm working on it. smile.gif
User is online!Profile CardPM
+Quote Post

gabehabe

RE: X-Twitter

30 Sep, 2008 - 11:51 AM
Post #3

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
Just gonna finish removing the HTML from the posts, and I'll upload the first version. I think you'll be pleasantly surprised. smile.gif
User is online!Profile CardPM
+Quote Post

gabehabe

RE: X-Twitter

30 Sep, 2008 - 12:23 PM
Post #4

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
Finally it's ready. Haven't made it parse the HTML in the tweets yet, but that's something to work on. For now, I'd love to get some feedback.

Here's some screenshots:

The main window:
IPB Image

The login form:
IPB Image

After logging in, please be patient~ I haven't put a loady thingy yet, so it looks like it isn't doing anything. In actual fact, it's connecting to your homepage and reading the 20 most recent tweets from you and your friends.

Here's the exe with source:
Attached File  Twitter.zip ( 119.04k ) Number of downloads: 14


I'd love to get feedback on this one, it's my first proper project for connecting to a web page behind the scenes.

smile.gif



Attached thumbnail(s)
Attached Image Attached Image
User is online!Profile CardPM
+Quote Post

born2c0de

RE: X-Twitter

1 Oct, 2008 - 05:26 AM
Post #5

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,542



Thanked: 98 times
Dream Kudos: 2825
Expert In: J2ME, 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
When the '@' character is used to refer to a twitter member, it partially shows the a href HTML tag instead of a link to the member.

When an update is posted, you could refresh the tweets so that our own tweet shows up in the list.

Fix these tiny bugs and you've got yourself a cool, slick app.

P.S : You seriously need to come up with better names for your projects. wink2.gif
User is offlineProfile CardPM
+Quote Post

Locke

RE: X-Twitter

1 Oct, 2008 - 07:25 AM
Post #6

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,943



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
...You need a job, so you don't work so much. laugh.gif biggrin.gif
User is offlineProfile CardPM
+Quote Post

gabehabe

RE: X-Twitter

1 Oct, 2008 - 07:26 AM
Post #7

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
laugh.gif I know, I suck at names.

Thanks for the feedback b2c happy.gif

And I've already done those things you said in the latest:
-Automatically updates the FriendPanels every 60 seconds.
-HTML has been removed in the tweets.
-It puts the screen name in brackets next to the real name.
-It says "logged in as" along with the username at the top.

3 downloads?
Out of curiosity, is there anyone here who would actually use it?

Things to add:
-Obviously it needs stabilising, it keeps crashing with this damn thread sleep.gif
-A little popup in the bottom right corner of the screen, like when you get an update on MSN
-Ability to add custom skins (it's only a background image anyway)
.......-Also add the ability to change the appearance of friend panels
-Make it possible to click the links in a tweet
-Ability to close a panel (hide the tweet) by clicking a little 'x'
-Clicking the user's name/image will open their profile
-Add the time/"from" bit to the friend panels, to show when the updates were posted
-Animation is a must for a slick GUI
-Tweet filtering, only seeing tweets from certain users
-Updating your profile (eg, changing the display picture)
-And more that I can't think of right now

whew, that's quite a bit~

And anyone with a better name? wink2.gif
User is online!Profile CardPM
+Quote Post

Locke

RE: X-Twitter

1 Oct, 2008 - 07:40 AM
Post #8

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,943



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
QUOTE(gabehabe @ 1 Oct, 2008 - 08:26 AM) *

And anyone with a better name? wink2.gif


Z-Twitter. laugh.gif biggrin.gif tongue.gif
User is offlineProfile CardPM
+Quote Post

gabehabe

RE: X-Twitter

1 Oct, 2008 - 11:39 AM
Post #9

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
Woohoo! X-Twitter just got approved on SourceForge! biggrin.gif
User is online!Profile CardPM
+Quote Post

baavgai

RE: X-Twitter

1 Oct, 2008 - 12:01 PM
Post #10

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,261



Thanked: 389 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
QUOTE(gabehabe @ 30 Sep, 2008 - 04:23 PM) *

I'd love to get feedback on this one, it's my first proper project for connecting to a web page behind the scenes.


Well, you asked for it. evil.gif

First,
csharp

} catch (Exception ex) {/* DO NOTHING */}


What could possibly go wrong? tongue.gif You should only ignore exceptions in very rare cases. At the very least, send something to the output window so you can tell something happened:

csharp

} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
}


One class per file. Java enforces this in a draconian fashion where C# doesn't, but that doesn't mean you shouldn't follow the model. Avoid struts, that Tweet object could probably be doing more work for you.

This business of the login from the main form and self closing, ick.
csharp

public partial class MainForm : Form {
void MainFormLoad(object sender, EventArgs e) {
Login login = new Login();
login.ShowDialog();
if (login.login == false)
this.Close();
else {


Putting it in the root is all together cleaner.
csharp

private static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Login login = new Login();
login.ShowDialog();
if (login.login) {
MainForm frm = new MainForm();
frm.SetLogin(login.username, login.password);
frm.ShowDialog();
}
}


Last, but not least, static is bad. It creates bad programming habits, grows hair on your palms, etc.

Now, a design hint. It looks like their pages are valid XHTML. Rather than playing string games, you might have an easier time with an XmlDocument and xpath.

Overall, well done. I'm rather surprised you've been working in the language for such a short time with no Java experience. Pity I have no interest in Twitter. tongue.gif

User is offlineProfile CardPM
+Quote Post

gabehabe

RE: X-Twitter

1 Oct, 2008 - 12:34 PM
Post #11

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
Thanks baavgai icon_up.gif

I'll take those tips into consideration in future~

I never even thought to put it in the root sleep.gif

I'll stick with the string games for now, I might update it in future to work as an XmlDocument.

Until then, here's the latest version:
Attached File  Twitter.zip ( 157.26k ) Number of downloads: 7


New features include automatic updates of the FriendPanels, and an MSN-style update in the bottom right corner of the screen. (I might have to move it up a bit, I forgot)

It's also a lot more stable.

As always, I'd love to get some feedback. smile.gif
User is online!Profile CardPM
+Quote Post

Locke

RE: X-Twitter

1 Oct, 2008 - 07:25 PM
Post #12

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,943



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
QUOTE(baavgai @ 1 Oct, 2008 - 01:01 PM) *

Overall, well done. I'm rather surprised you've been working in the language for such a short time with no Java experience. Pity I have no interest in Twitter. tongue.gif


Hell, I've got more Java experience than he's got C# experience (in terms of time), but I have a college life to attend to...and a C++ class, so I don't have a lot of time to play around and learn as quick as he does in languages that I like...such as Java. I wouldn't know the first thing about connecting to a web page...He's certainly got more experience in C# than I do in Java (in terms of skill).

By the way...C++ is far too complicated for it's own good...sleep.gif

This post has been edited by Locke37: 1 Oct, 2008 - 07:28 PM
User is offlineProfile CardPM
+Quote Post

gabehabe

RE: X-Twitter

2 Oct, 2008 - 01:20 AM
Post #13

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
@Locke:
You've done some .NET stuff, so try these 2 snippets:

Get a Bitmap directly from the web

Post an Update to a Twitter Account

Hopefully they'll make enough sense for you to figure it out.

Maybe I'll write a tutorial~ (If Psycho hasn't already beaten me to it) tongue.gif
User is online!Profile CardPM
+Quote Post

gabehabe

RE: X-Twitter

2 Oct, 2008 - 04:46 AM
Post #14

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
I'm currently working on adding an intellisense-like feature to the text box. Basically, if you type '@' it will list all the people you're following in a listbox from where the caret is (Like intellisense, basically)

smile.gif
User is online!Profile CardPM
+Quote Post

baavgai

RE: X-Twitter

2 Oct, 2008 - 07:25 AM
Post #15

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,261



Thanked: 389 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Just some code I compulsively wrote while looking at yours. As a user, and a tester, I'd still like to see some feedback when things go south.

From a design standpoint, I hate having gui and logic all clumped up together. I don't like that the form is the keeper of the current username and password. This is actually where having a real object, as opposed to all that static crap, is useful.

The idea is to have one object that keeps the current user's login info. That object is then responsable for all your calls to the datasource, in this case a website.

I used the "users show" twitter page for validation, which may be a little quicker. This probably isn't perfect, I wrote it this morning and have to stop now. I thought about keeping it to myself, but there's a chance you might find something useful and it wouldn't be fair not to share:

csharp

using System;
using System.Web;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Xml;

namespace TweetTest {
public class TwitterUserInfo {
private string id, name, screenName, location, description, profileImageUrl;

public TwitterUserInfo(string id, string name, string screenName, string location, string description, string profileImageUrl) {
this.id = id;
this.name = name;
this.screenName = screenName;
this.location = location;
this.description = description;
this.profileImageUrl = profileImageUrl;
}

public string Id { get { return this.id; } }
public string Name { get { return this.name; } }
public string ScreenName { get { return this.screenName; } }
public string Location { get { return this.location; } }
public string Description { get { return this.description; } }
public string ProfileImageUrl { get { return this.profileImageUrl; } }

public override string ToString() {
return string.Format("UserInfo({0}): {1} : {2}", this.id, this.screenName, this.name);
}
}


public class TwitterUser {
private string username;
private ICredentials creds;
private TwitterUserInfo info = null;

public TwitterUser(string username, string password) {
this.username = username;
this.creds = new NetworkCredential(username, password);
this.info = GetUserInfo(this.username);
}
public string Username { get { return this.username; } }

public TwitterUserInfo Info { get { return this.info; } }

public bool IsAuthenticated { get { return this.info!=null; } }


protected HttpWebRequest GetBaseRequest(string url) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = this.creds;
request.ContentType = "application/x-www-form-urlencoded";
return request;
}

protected HttpWebRequest GetBaseRequest(string url, string message) {
HttpWebRequest request = GetBaseRequest(url);
request.Method = "POST";
request.ContentLength = message.Length;
using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)) {
writer.Write(message);
}
return request;
}

protected string ResponseToString(HttpWebRequest request) {
string res = null;
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
res = reader.ReadToEnd();
}
}
} catch (Exception ex) {
Debug.WriteLine("ResponseToString Error: " + ex.Message);
}
return res;
}

protected string GetString(XmlDocument xmlDoc, string path) {
XmlNode node = xmlDoc.SelectSingleNode(path);
if (node == null) { return null; }
return node.InnerText;
}

public TwitterUserInfo GetUserInfo(string user) {
string res = ResponseToString(GetBaseRequest("http://twitter.com/users/show/" + user + ".xml"));
if (res==null) { return null; }
XmlDocument xmlDoc = new XmlDocument();
try {
xmlDoc.LoadXml(res);
} catch (Exception ex) {
Debug.WriteLine("GetUserInfo Error: " + ex.Message);
return null;
}

return new TwitterUserInfo(
GetString(xmlDoc, "user/id"),
GetString(xmlDoc, "user/name"),
GetString(xmlDoc, "user/screen_name"),
GetString(xmlDoc, "user/location"),
GetString(xmlDoc, "user/description"),
GetString(xmlDoc, "user/profile_image_url"));
}

public string SendTweet(string text) {
if (string.IsNullOrEmpty(text)) { return null; }
return ResponseToString(GetBaseRequest("http://twitter.com/statuses/update.xml",
"status=" + HttpUtility.UrlEncode(text)));
}

}

class Program {
static void Main(string[] args) {
TwitterUser user = new TwitterUser("baavgai", "password");
Debug.WriteLine(user.Info);
Debug.WriteLine(user.SendTweet("You message here"));
Debug.WriteLine("Done");
}
}

}


User is offlineProfile CardPM
+Quote Post

gabehabe

RE: X-Twitter

2 Oct, 2008 - 07:42 AM
Post #16

Sexy DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 8,830



Thanked: 175 times
Dream Kudos: 3275
Expert In: Lots of things.

My Contributions
I'm impressed. Looking at your code, it makes me realise I've got a long way to go before I'm a pro. My code is always all over the place. sad.gif

I haven't really got much use for it, since I don't really want to rewrite it again~

But that's definitely taught me a thing or twenty about program structure.

Thanks icon_up.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:06AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month