Check with @mattosborn. His code uses the preference URL ...

https://gist.github.com/mattosborn/2a7643927910ca7aea54