Digg.com API for ASP.NET (VB)

Below is the code needed to use Digg.com’s API which is in REST instead of .NET’s webservice standard, SOAP.

Usage is simple:

  • copy the function to your page
  • Import System.Net
  • call the function while passing the required endpoint and your valid diggKey ( a standard url like: http://192.241.150.159 )
  • it will return a DataSet with the required info!

Thanks to Gaskell.org for providing the C# version of this!


Shared Function diggRaw(ByVal myEndPoint As String, ByVal diggKey As String) As Data.DataSet
 Try
  Dim myURL As String = "http://services.digg.com/" & myEndPoint & "?appkey=" & diggKey
  Dim myReq As HttpWebRequest = WebRequest.Create(myURL)
  myReq.UserAgent = ".Net"
  Dim myResp As HttpWebResponse = myReq.GetResponse()
  Dim myStream As New System.IO.StreamReader(myResp.GetResponseStream)
  Dim myDS As New Data.DataSet("Digg")
  myDS.ReadXml(myStream)
  Return (myDS)
 Catch ex As WebException
  'If there's an error, return a dataset named "Error"
  'You can just check the .DatasetName to see if it's an error.
  'If it IS an error, Table(0).Row(0).Item(0) will contain the message.
  Dim myError As New DataSet("Error")
  Dim myTable As New DataTable("Error")
  myTable.Columns.Add("Message")
  Dim myRow As DataRow = myTable.NewRow
  myRow("Message") = ex.Message
  Return (myError)
 End Try
End Function