1 Replies - 272 Views - Last Post: 05 July 2012 - 06:24 AM Rate Topic: -----

#1 ncncnc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Twitter in Forms

Posted 05 July 2012 - 06:11 AM

Hi all,

I'm currently adding the finishing touches to a system I have made. I thought it would be nice to add some twitter integration. I'm trying to use the below code I found on a tutorial. It seems sound to me but It's not working. Does anybody have any idea why or if there is a better way of doing it?

 public static void PostTweet(string username, string password, string tweet)
        {
            
               
                // 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; // thanks to argodev for this recent change!
                // 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();
            
        }


I call the method with the following

PostTweet("My username", "My password", "Test");


Is This A Good Question/Topic? 0
  • +

Replies To: Twitter in Forms

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3419
  • View blog
  • Posts: 10,530
  • Joined: 05-May 12

Re: Twitter in Forms

Posted 05 July 2012 - 06:24 AM

What errors are you getting?

I think the code that you found is outdated. Here's the current Tweet API for posting: https://dev.twitter....statuses/update

And if I recall, you now have to login using OAuth -- basic authentication is not supported anymore.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1