Livefyre's node.js library provides methods for common tasks for working with Livefyre. Some of these methods can be particularly useful for one-off tasks such as testing API calls.
This guide demonstrates how to use the Livefyre node.js library from the command line to assist in those tasks. It assumes you are familiar using the command line on your system of choice, but not necessarily node.js.
Download and install node.js on your system from nodejs.org. Make sure that this is registered in your PATH/Environment variables so that the commands 'node' and 'npm' are available from the command line.
- Create a folder to act as a workspace
- Navigate to this folder in the command line
- Install the Livefyre library using npm:
$ mkdir livefyre
$ cd livefyre
$ npm install Livefyre
NPM is node's package manager. Given a package name, it will download the library into a folder called node_modules inside your working folder. When running node from your workspace folder, all of the modules in the node_modules folder will be available to you. ('livefyre' is the registered name for Livefyre's library within npm.)
To use the library from the command line, simply load it using the require
statement.
// Launch node
$ node
> var Livefyre = require('Livefyre');
Livefyre tokens are used by api calls that require authentication. By default, the buildLivefyreToken() method generates a token that is valid for 24 hours.
// Load the library
> var Livefyre = require('Livefyre');
// Initialize the Network Object
> var network = Livefyre.getNetwork('your-network.fyre.co','your-network-key');
// Output a token
> network.buildLivefyreToken();
You can generate a Livefyre Token with a different TTL by calling buildUserAuthToken() for the 'system' user. Both the displayname and id of this user is 'system'.
// Load the library
> var Livefyre = require('Livefyre');
// Initialize the Network Object
> var network = Livefyre.getNetwork('your-network.fyre.co','your-network-key');
// Output a UserAuth Token for the system user, for 30 days
> network.buildUserAuthToken('system','system',2592000);
TTL is defined in seconds. Livefyre accepts a maximum of 45 days. Here is a list of common values:
- 48 Hours: 172800
- 7 Days: 604800
- 30 Days: 2592000