Använda Spotify MetaData API i Ruby

Spotify har släppt ett API för att kunna hämta information om låtar via deras Spotify-url:er. Nedan är ett exempel i Ruby på hur du kan hämta artist och låt. Anropas med ex. spotify:track:4KPU7XGqxo4UlMp3is7NBI

def getTitleFromSpotifyTrack(trackID)
    require 'net/http'
    require 'rexml/document'
    require 'rexml/xpath'

    res = Net::HTTP.get_response(URI.parse("{trackID}"))
    contents = res.body

    doc = contents

    track = REXML::XPath.first(doc,'/track/name/text()')
    artist = REXML::XPath.first(doc,'/track/artist/name/text()')

    return "#{artist} - #{track}"

4 replies on “Använda Spotify MetaData API i Ruby”

Hello ,
I’m Angelina.
If you’ve ever been too busy and couldn’t finish a academic paper, then you’ve come to the right place. I work with students in all areas of the writing steps . I can also write the assignment from start to finish.
My career as a professional writer started during high school. After learning that I was very able in the field of academic writing, I decided to take it up as a job .

Talented Academic Writer- Angelina- How to Teach Students to Write an Essay Band

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.