Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

last.fm.api

Package Overview
Dependencies
7
Maintainers
1
Versions
3
Issues
File Explorer

Advanced tools

last.fm.api

last.fm.api with Promises and ES6 style classes

    0.1.3latest

Version published
Maintainers
1
Yearly downloads
4,783
increased by170.53%

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

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc