There is a compiled command line application here that does this.
Is there a Cocoa API to query this data?
You can try SMSLib, which is an open-source Objective-C library for accessing the sudden motion sensor.