Skip to content

Instantly share code, notes, and snippets.

@pcolombo
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcolombo/7f1fd498925b08ff002f to your computer and use it in GitHub Desktop.
Save pcolombo/7f1fd498925b08ff002f to your computer and use it in GitHub Desktop.
Guide to use the Livefyre node.js library from the command line.

Using Livefyre's node.js Library from the Command Line

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.

Install 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.

Install the library

  1. Create a folder to act as a workspace
  2. Navigate to this folder in the command line
  3. 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.)

Using the Library from the command line

To use the library from the command line, simply load it using the require statement.

// Launch node
$ node

> var Livefyre = require('Livefyre'); 

Common Tasks

Building a Livefyre Token

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();

Building a Livefyre Token with a different TTL

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment