Posted by michaeljbyers on 10. June 2009 18:23
Following my previous article on Dynamically updating Twitter with Twitterizer and TinyURL Edward Lewis suggested I use bit.ly to shrink the URL. So here is the code to do that:
Public Shared Function MakeBitlyUrl(ByVal Url As String) As String
Try
If Url.Length <= 30 Then
Return Url
End If
If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
Url = "http://" & Url
End If
Dim request As Net.HttpWebRequest = WebRequest.Create("http://api.bit.ly/shorten?version=2.0.1&longUrl=" + HttpUtility.UrlEncode(Url) + "&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07")
Dim Response As WebResponse = request.GetResponse
Dim res = request.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(Response.GetResponseStream)
Dim text As String = sr.ReadToEnd
sr.Close()
Dim indexOfBefore As Integer = text.IndexOf("shortUrl"": """) + 12
Dim indexOfAfter As Integer = text.IndexOf("""", indexOfBefore)
Dim shortURL As String = text.Substring(indexOfBefore, indexOfAfter - indexOfBefore)
Return shortURL
Catch generatedExceptionName As Exception
Return Url
End Try
End Function
Thanks also to Using bit.ly URL Shortening From ASP.NET (REST/JSON) for a great code example.
8e27b307-0ce1-4cb0-8191-c37c8b12f578|0|.0
Comments: 0
Filed Under: .Net
Tags:
.net,
twitter
Posted by michaeljbyers on 2. June 2009 15:52
Further to my previous post Twitter API and .NET I have been working on a way to dynamically update my Twitter status from my .NET web application. To get this to work I have used Twitterizer and TinyURL.
Twitterizer makes it very easy to implement. I also wanted to make sure I could also shrink the urls so I used TinyURL for this.
To start the vb class you will need the following:
Imports Twitterizer.Framework
Public Class TwitterUtils
Private Shared twitter_username As String = "YourTwitterUserName"
Private Shared twitter_password As String = "YourTwitterPassword"
The VB code for shrinking the url with TinyURL:
Public Shared Function MakeTinyUrl(ByVal Url As String) As String
Try
If Url.Length <= 30 Then
Return Url
End If
If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
Url = "http://" & Url
End If
Dim request As Net.HttpWebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" & Url)
Dim Response As WebResponse = request.GetResponse
Dim res = request.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(Response.GetResponseStream)
Dim text As String = sr.ReadToEnd
sr.Close()
Return text
Catch generatedExceptionName As Exception
Return Url
End Try
End Function
To update my status on Twitter I used the following code:
Public Shared Sub updateStatus(ByVal post As String)
Dim RegexObj As Regex = New Regex("(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?")
Dim t As New Twitter(twitter_username, twitter_password)
t.Status.Update(RegexObj.Replace(post, TwitterUtils.MakeTinyUrl(Regex.Match(post, "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?").Groups(0).ToString)))
End Sub
As you can see I used a regular expression to replace the url in the text with a TinyURL.
You may want to have a textbox and a seperate url field. To submit these you could use the following code:
Public Shared Sub updateStatus(ByVal post As String, Optional ByVal url As String = "")
Dim new_status As String = String.Empty
If Not url Is Nothing Then
If post.Length > 114 Then
post = post.Substring(0, 114)
End If
new_status += post & " " & MakeTinyUrl(url)
Else
new_status += post
End If
Dim t As New Twitter(twitter_username, twitter_password)
t.Status.Update(new_status)
End Sub
Twitterizer makes it simple to update your status using .NET. I have only used it for updating my status but you can use it for Direct Messages and Replies. Why not download it and start using it in your own web applications.
If you are on Twitter leave your username here for others to follow.
1f5a1faa-58b6-4287-8063-a54d9b54f22c|0|.0
Comments: 0
Filed Under: .Net
Tags:
twitter,
.net
Posted by michaeljbyers on 2. June 2009 15:13
A list of Scottish Councils on Twitter:
Posted by michaeljbyers on 2. May 2009 13:02
I have been working on implementing the Twitter api into a .Net website. After some searching I discovered Twitterizer. It is a .Net dll that you can include in your project. This has made it easy for me to update my status dynamically. The problem I did find was that the URL posted was not being shrunk.
So using tinyurl I was able to include some code to convert the url to a tinyurl and post it. I found this article Shortening URLs Using TinyURL API in .NET and using the code provided I was able to shorten the url for posting.
I am currently demoing this to a client and will keep you updated on my progress.
5e6f76b0-c23c-431c-b23b-73f105357d98|0|.0
Comments: 1
Filed Under: .Net
Tags:
twitter,
.net
Posted by michaeljbyers on 2. May 2009 12:51
I just launched the golf events blog for South Ayrshire Council. The blog will provide information on the golf events in South Ayrshire.
It is using blogengine.net and is the first blog from South Ayrshire Council.
In South Ayrshire, Golf is a way of life.
South Ayrshire is often referred to as Scotland's golf coast. This stunning coastline boasts the inaugural home of The Open Championship, two out of five current Scottish Open venues and a range of private and public courses each boasting their own unique character. Full details from www.golfsouthayrshire.com.
Posted by michaeljbyers on 15. April 2009 15:36
Keywords on your webpage help search engines categorise your webpage. Keywords are what people use to search for information. If you wanted to find out about search engine optimisation then you would probably use that phrase or a similar phrase like seo tips. But what if you wanted to research what keywords are best for your webpage or check that you don't use too few keywords?
There are many keyword tools that can help you by analysing and checking your keyword density. Content is what matters so don't over use keywords on your page. Here is a list of some keyword checkers that will help you get the balance right:
- goRank keyword density analyzer
- Keyword density analyzer
- Marketleap keyword verification
- Motoricerca keyword density analyzer
- Ranks.nl keyword density and prominence
- SEOBook keyword density analyzer tool
- SEOchat keyword density tool
- SEOchat keyword difficulty check
- Keyword density analyser
- Webpage analyser
- Word counter
- Yellowpipe keyword frequency counter