You are not logged in. Please log in if you wish to participate in all discussions on the website, chat with friends, and use everything we've got to offer.

Click Register below to, well, register. Derp. Enjoy your stay. ;)

If you do not have an account and wish to create one, please follow the link below.

http://www.robloxtoday.net/register

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

ihaveamac


Telamon
Make a Visual C# program tweet to

You will need:
1. Microsoft Visual C# Express or not (2008 recommended)
2. Internet
3. Use to any Twitter.com account
4. Some skill with C#

1. Open C#
2. Make a new project.
3. Select "Windows Forms Application"
4. Name your project something like "Tweeting Application" Anything without the word "twitter" in it. (Really, don't put "twitter" in the name)

This seems like an easy tutorial, huh? Not! ;)

5. Insert 3 Textboxes. Name them these:
usernameBox
passwordBox
tweetBox

Edit the textboxes. Now, we're not making them save, that's not needed now.
5a. In the properties, set the passwordBox's "PasswordChar" to * (shift 8)
5b. Set the tweetBox's "MultiLine" to True, and make the box taller.
6. Add a button below the tweet box, name it "tweetButton", and set it's text to "Update status".
Random: Make a group box and put the tweetBox into it, and set the group box's Text to "What are you doing?" just to be funny. :P You don't have to.
Here it comes! The "Fun" part has come! Coding!
7. Double-click the tweetButton. You will see a code editor.
Warning! Check where it says stuff like "using System.blahblah;". Insert the following below all the "using" lines:
Code:
using System.Net;
using System.Web;
using System.IO;

If you do NOT include those, the tweeting will not work.
8. Do NOT edit anything that says this yet:
Code:
private void tweetButton_Click(object sender, EventArgs e)
{

}

Below this part:
Code:
public Form1()
{
InitializeComponent();
}

Insert these lines of code: (Warning: Very long) All lines needed, don't edit/miss anything in these
Code:
public static void PostTweet(string username, string password, string tweet)
{
try
{
// encode the username/password
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username ":" password));
// determine what we want to upload as a status
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet);
// connect with the update page
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml");
// set the method to POST
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
// set the authorisation levels
request.Headers.Add("Authorization", "Basic " user);
request.ContentType = "application/x-www-form-urlencoded";
// set the length of the content
request.ContentLength = bytes.Length;
// set up the stream
Stream reqStream = request.GetRequestStream();
// write to the stream
reqStream.Write(bytes, 0, bytes.Length);
// close the stream
reqStream.Close();
}
catch (Exception ex)
{
MessageBox.Show("An error occured when posting your tweet.\n\nError: " ex.Message);
}
}

*phew* We got the important part done...
9. Now where it says this:
Code:
private void tweetButton_Click(object sender, EventArgs e)
{

}

Type in something to make it look like this:
Code:
private void tweetButton_Click(object sender, EventArgs e)
{
PostTweet(usernameBox.Text, passwordBox.Text, tweetBox.Text);
}

10. Type in a Twitter.com username into the usernameBox, password into the passwordBox, and text into the tweetBox, then send it by pressing the tweet button!
Check twitter.com, and look.

Comments? Questions? Post below!

View user profile

jbw1394


Experienced Robloxian
Experienced Robloxian
Looks interesting. How do we get older versions of Visual C#?

View user profile

ihaveamac


Telamon
jbw1394 wrote:Looks interesting. How do we get older versions of Visual C#?

An express edition is available at http://www.microsoft.com/express

View user profile

jbw1394


Experienced Robloxian
Experienced Robloxian
Oppss I downloaded the 2008 version before lol

View user profile

ihaveamac


Telamon
This "Make a visual c# program tweet to twitter" thing works. I actually tried it. :D Thing is, it says "from API." :(

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum