Socket
Socket
Sign inDemoInstall

last.fm.api

Package Overview
Dependencies
57
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    last.fm.api

last.fm.api with Promises and ES6 style classes


Version published
Weekly downloads
242
increased by4.31%
Maintainers
1
Install size
5.29 MB
Created
Weekly downloads
 

Readme

Source

last.fm.api

Build Status

Wrapper for Last.FM API v2 with ES6 style classes and promises. Supports Desktop, Web and Mobile auth. http://www.last.fm/api

Prerequisites

You need an API key and secret:

Install

npm install last.fm.api --save

Usage

All API methods listed in the developer documentation http://www.last.fm/api are mapped to the API class. e.g. api.album.getTags() for the API method album.getTags. You do not need to supply api_sig and api_key to the methods, these will be generated automatically. You must supply sk (session key) for methods that require it.

'use strict';

const API = require('last.fm.api'),
    api = new API({ 
        apiKey: '<YOUR API KEY>', 
        apiSecret: '<YOUR API SECRET>'
    });

API

new API(options);

  • apiKey String - Your API key
  • apiSecret String - Your API secret
  • debug Boolean - If true the URL and Querystring/Form Body are written to the console. (default false)
  • username String - Your Last.FM username, required when using authentication for Mobile apps (optional)
  • password String - Your Last.FM password, required when using authentication for Mobile apps (optional)

Examples

There are a lot of examples in the /examples folder which I've tried to comment thoroughly. Likewise there are examples of Desktop, Mobile and Web Authorisation.

'use strict';

const API = require('last.fm.api'),
    api = new API({ 
        apiKey: '<YOUR API KEY>', 
        apiSecret: '<YOUR API SECRET>'
    });

api.album.getTags({
    artist: 'nirvana',
    album: 'nevermind'
})
    .then(tags => { console.log(tags); })
    .catch(err => { console.error(err); });

/*
// tags = ...
{
    "tags": {
        "tag": [{
            "name": "metal",
            "url": "http://www.last.fm/tag/metal"
        }, {
            "name": "punk",
            "url": "http://www.last.fm/tag/punk"
        }, {
            "name": "Grunge",
            "url": "http://www.last.fm/tag/Grunge"
        }, {
            "name": "noise",
            "url": "http://www.last.fm/tag/noise"
        }],
        "@attr": {
            "artist": "Nirvana",
            "album": "Nevermind"
        }
    }
} */

To get a session key for mobile apps

'use strict';

const API = require('last.fm.api'),
    api = new API({ 
        apiKey: '<YOUR API KEY>', 
        apiSecret: '<YOUR API SECRET>',
        debug: true,
        username: '<YOUR USERNAME>',
        password: '<YOUR PASSWORD>'
    });

// Get Mobile Session by supplying username and password into API constructor
api.auth.getMobileSession({})
    .then(json => json.session)
    .then(session => {
        console.log('session', session);
        process.exit();
    })
    .catch(err => {
        console.error('ERRORED!', JSON.stringify(err));
        process.exit();
    });

/*
// result = ...
{
    "subscriber": 0,
    "name": "<YOUR USERNAME>",
    "key": "<SESSION KEY>"
} */

Keywords

FAQs

Last updated on 16 Jun 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc