Working With Social Network APIs

Creating Vicinity Buzz naturally involved working with a the APIs of social networks. That information seemed worth sharing for those of you interested in writing any type of application that would integrate with a social network.

Developer Documentation

Any of the social networking sites you probably want to integrate with have developer api’s that are well documented. Here’s the starting points for a variety of services:

Working With JSON

All of these APIs are best used with JSON. If you’re not familiar, you can read up at json.org. It’s the notation for serialization of javascript objects, and object literals.

Where To Make the Call From

If you are working in a standard web page, you could call the api from document.ready (assuming you are using jquery). This is the approach I take on hoolihan.net, my personal homepage. There is a twitter feed on the right side.

If you have a bit more of an application, you may want to look at one of the many javascript frameworks that help you route events to actions. These are frameworks like backbone, knockout, spine, etc. There are also commercial variants like kendo, dojo, and sencha.

jQueryMobile is commonly paired with PhoneGap, and in that scenario, using something like backbone is a bit tricky. You may want to bring in a template binding library, but avoid routing.

Binding

jQuery.templates was one of the first good javascript template binders that I’m aware of, but there are now many different options. In the jQuery world, most of the momentum seems aimed at jsrender. Recently I’ve considered bring in knockout and only using the binding part, but I’m not far enough in to evaluate that direction.

API Keys

Unless you’re using the most basic parts of the API, you’ll probably need to register your app and get an API key. It’s a token that identifies your application. In the event of API abuse (too many calls, etc), they have information to contact you and analytics around the issue.

Open Authentication

This is a big topic, but if your application wants to use a social network to identify your users, this is possible via open authentication. If you are interested in this, get started here.

What Do You Think?

Are there any particular areas of the APIs that you’d like to see more detail about? Any conceptual parts that would warrant their own post? Let me know what you think below.

Write and Validate XML with a DTD in Memory in .Net

This is the sample of piecing together a lto of different posts, so I thought I’d put a sample on the web…

I’m putting it in VB.Net (because I was writing in it due to project requirements

Imports System.Xml
Imports System.Xml.Schema
Imports System.Text
Imports System.IO

Public Class MyXMLTool
  Private sb As New StringBuilder(“”)
  Private xw As XmlWriter
  Private validXml As Boolean = True
  Private validationErrors As String = “”

  Public Sub New()
  End Sub

  Public ReadOnly Property ValidationMessages() As String Implements
   Get
     Return validationErrors
   End Get
  End Property

  Public Function Prepare() As Boolean Implements iEnroller.Prepare
    xw = XmlWriter.Create(sb)
    xw.WriteStartDocument()
    xw.WriteDocType(“MyRootElement”, Nothing, “MyDTD.dtd”, “<!– This file represents my data –>”)
    xw.WriteStartElement(“MyRootElement”)
    ‘Write everything else you want to write
    xw.WriteEndElement()

    xw.WriteEndDocument()
    xw.Close()
    Return True
  End Function

  Public Function Validate() As Boolean
     Dim xs As New XmlReaderSettings()
    xs.ProhibitDtd = False
    xs.ValidationType = ValidationType.DTD
    AddHandler xs.ValidationEventHandler, New ValidationEventHandler(AddressOf ValidationCallback)

    Dim sr As New StringReader(sb.ToString())
    Dim xr As XmlReader = XmlReader.Create(sr, xs)

    ‘this forces the validation process to occur by reading every line
    While xr.Read
    End While

    ‘this will be set False if the ValidationCallback happens
    Return validXml
  End Function

  Public Sub ValidationCallback(ByVal sender As Object, ByVal e As ValidationEventArgs)
    validXml = False
    validationErrors = e.Message
  End Sub

  Public Sub GetXML() as String
    return sb.ToString()
  End Sub
End Class