Once you have Node installed, starting up is as simple as downloading the code, installing NPM dependencies and running the server.
git clone git://github.com/Singly/nodejs_express_skeleton.git cd nodejs_express_skeleton npm install node app.js
But if you try to access one, you'll get the error
client_id and redirect_uri required
If you haven't already registered an application, do that now on the Application Mangement page. Make sure your settings include the right URLS:
URLThe url that users will eventually be able to access your app (can be changed later).
These must match the hostname you're loading the skeleton from, or authorization will fail. For more on using OAuth2 with Singly, see the authorization documentation.
The example uses the the
environment variable. If you have foreman you can set them in a
.env file. If not, you can simply set them as local environment variables:
export SINGLY_CLIENT_ID=<clientID> export SINGLY_CLIENT_SECRET=<clientSecret>
and start the app directly:
clientSecret are shown on your application settings page after
After you start your server with the correct client ID and secret, you'll be able to authorize using any of the listed services. That uses the OAuth2 flow, which starts out at a URL like
where the query parameters are
client_idThe clientID you used when you started the server
serviceThe service the user wants to authorize with, eg. Facebook or Twitter
redirect_uriThe URL on your server the user is sent back to after they log in to
service. This must match the
Callback URLyou provided in your application settings.
Now if you click on a service you've authorized, instead of being asked to log in, you'll be taken to that service's profile summary. If you're quick, you can refresh that page and see the initial sync of your data from that service. The URL we're hitting now is fully documented with the service endpoints and is of the form
SERVICE is one of the services you just authorized and
TOKEN is the
token we got back during the
code exchange. All API endpoints require the
access_token parameter and give back data only for the user associated with
that token, except for the
/services endpoint which provides a simple list of
availble services and the data provided by each.
Now you know how authorization works and how to get data from the Singly API. It's a simple JSON API, so you can access it anywhere you like so long as you have someone's token. To speed you up, there are client packages available for Node and Ruby.
You can also see the shape of the API and explore your own data with the API Explorer.
If you're running your server somewhere other than
localhost, you can set the
HOST environment variables. This hostname must match your appliation settings.
By default, the skeleton runs against https://api.singly.com, but if you're working on your own version of the API, you can provide that too. This is not at all required to run your node example, and to get going you should just use https://api.singly.com.
We love feedback our this walkthrough and the rest of our documentation. If there was any part of this that was wrong, unclear, or otherwise tripped you up, file an issue or come talk with us live on HipChat.