This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-08-30 03:11:31

ihaveamac
Scratcher
Registered: 2007-09-22
Posts: 1000+

Make a Visual C# program tweet to Twitter

tongue

Make a Visual C# program tweet to
http://a0.twimg.com/a/1251493570/images/twitter_logo_header.png

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!  wink

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.  tongue  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:

        /// <summary>
        /// Post an update to a Twitter acount
        /// </summary>
        /// <param name="username">The username of the account</param>
        /// <param name="password">The password of the account</param>
        /// <param name="tweet">The status to post</param>
        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!

Last edited by ihaveamac (2009-08-30 03:11:58)


~ihaveamac - visit ihaveamac.net

Offline

 

#2 2009-08-30 04:20:16

ihaveamac
Scratcher
Registered: 2007-09-22
Posts: 1000+

Re: Make a Visual C# program tweet to Twitter

bump..


~ihaveamac - visit ihaveamac.net

Offline

 

#3 2009-08-30 06:40:27

hirandomperson
Scratcher
Registered: 2009-01-02
Posts: 89

Re: Make a Visual C# program tweet to Twitter

how do you do it in python?

Offline

 

#4 2009-08-30 06:56:54

ihaveamac
Scratcher
Registered: 2007-09-22
Posts: 1000+

Re: Make a Visual C# program tweet to Twitter

hirandomperson wrote:

how do you do it in python?

i don't know, google it. i only know how to do it for C#


~ihaveamac - visit ihaveamac.net

Offline

 

#5 2009-09-04 18:18:56

hirandomperson
Scratcher
Registered: 2009-01-02
Posts: 89

Re: Make a Visual C# program tweet to Twitter

i figered out

Offline

 

#6 2009-09-04 18:23:34

iamrpk
Scratcher
Registered: 2009-04-06
Posts: 1000+

Re: Make a Visual C# program tweet to Twitter

Ummm...what exactly does it do? (lol I really don't know)


http://www.punbb-hosting.com/forums/AwesomeBooks911Forum/index.php

Offline

 

Board footer