How to make a simple Twitter post via ASP.NET (preferably VB)?

I don’t want to do anything interesting on Twitter other than posting to it through my site once a day. I was looking a bit, and there are all kinds of super-sophisticated ways to do every little thing Twitter does, but there seems to be little documentation on how to do the simplest thing that does the message!

Does anyone know how to do this? Or can you at least point me in the right direction? I don't need full wrappers or anything ( http://apiwiki.twitter.com/Libraries#C/NET ), just one simple function that will be posted on Twitter.

Thanks!

+4
source share
4 answers

This is the easiest implementation. Launch and launch in less than 2 minutes: Twitterizer

+4
source

There are several different ways to do this; they vary depending on the tools you want to use and which have access. Option 1 will work right out of the box, but coding can be complicated. Option 3 you will need to download the tools, but after installation and download you can very quickly use twitter api.

Here is an example of using the WCF REST Starter Kit HttpClient:

public void CreateFriendship(string friend) { using (var client = new HttpClient()) { var url = string.Format("http://www.twitter.com/friendships/create/{0}.xml?follow=true", friend); client.Post(url) .CheckForTwitterError() .EnsureStatusIs(HttpStatusCode.OK); } } 

Add a comment if you need more information about a particular method.

Update:

For option # 1, see this question: Remote HTTP C #

0
source

Its quite simple; you just need to send the xml file to the web page using webrequest.create. This example is close (it is assumed that you have xml for the message elsewhere and just pass it to the twitterxml variable as a string. Perhaps the URL is not correct, found it on this [page] [1], which defines the interface

 WebRequest req = null; WebResponse rsp = null; try { string twitterXML = "xml as string"; string uri = "http://twitter.com/statuses/update.format"; req = WebRequest.Create(uri); //req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy req.Method = "POST"; // Post method req.ContentType = "text/xml"; // content type // Wrap the request stream with a text-based writer StreamWriter writer = new StreamWriter(req.GetRequestStream()); // Write the XML text into the stream writer.WriteLine(twitterXML); writer.Close(); // Send the data to the webserver rsp = req.GetResponse(); } 

[1]: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses update

0
source

There are several ways to do this, you can check http://restfor.me/twitter and it will provide you the code from the RESTful documentation.

Essentially, with any authenticated call, you can follow this logic:

 /// /// Executes an HTTP POST command and retrives the information. /// This function will automatically include a "source" parameter if the "Source" property is set. /// /// The URL to perform the POST operation /// The username to use with the request /// The password to use with the request /// The data to post /// The response of the request, or null if we got 404 or nothing. protected string ExecutePostCommand(string url, string userName, string password, string data) { WebRequest request = WebRequest.Create(url); request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { request.Credentials = new NetworkCredential(userName, password); byte[] bytes = Encoding.UTF8.GetBytes(data); request.ContentLength = bytes.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); using (WebResponse response = request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { return reader.ReadToEnd(); } } } } return null; } 
0
source

All Articles