### Install Gobble.fm Go Library Source: https://github.com/twoscott/gobble-fm/blob/master/README.md Instructions for installing the Gobble.fm Go library using the `go get` command, which fetches the module and its dependencies. ```Go go get github.com/twoscott/gobble-fm ``` -------------------------------- ### Fetch Recent Tracks from Last.fm API in Go Source: https://github.com/twoscott/gobble-fm/blob/master/README.md A complete Go example demonstrating how to fetch a user's recent tracks from the Last.fm API using Gobble.fm, including error handling for API-specific errors and formatting the output with track details and scrobble times. ```Go package main import ( "errors" "fmt" "time" "github.com/twoscott/gobble-fm/api" "github.com/twoscott/gobble-fm/lastfm" ) func main() { fm := api.NewClientKeyOnly("API_KEY") params := lastfm.RecentTracksParams{ User: "Username", Limit: 5, From: time.Now().Add(-24 * time.Hour), } res, err := fm.User.RecentTracks(params) if err != nil { var fmerr *api.LastFMError if errors.As(err, &fmerr) { switch fmerr.Code { case api.ErrInvalidParameters: fmt.Println("Invalid parameters") case api.ErrOperationFailed: fmt.Println("Operation failed") default: fmt.Println(err) // ... } } else { fmt.Println(err) } return } for i, t := range res.Tracks { fmt.Printf("%d.\t%s by %s\n", i+1, t.Title, t.Artist.Name) if t.NowPlaying { fmt.Println("\tNow playing...") } else { ago := time.Since(t.ScrobbledAt.Time()).Truncate(time.Second) fmt.Printf("\tScrobbled %s ago\n", ago) } fmt.Printf("\n\tArt: %s\n", t.Image.OriginalURL()) fmt.Println() } } ``` -------------------------------- ### Instantiate Low-Level Last.fm API Clients in Go Source: https://github.com/twoscott/gobble-fm/blob/master/README.md Shows how to instantiate low-level API clients in Go for direct request methods or authenticated session management, requiring manual session key handling for authenticated calls. ```Go import "github.com/twoscott/gobble-fm/api" // Provides methods for making API requests such as Get, Post, and Request. fm := api.New("API_KEY", "SECRET") ``` ```Go import "github.com/twoscott/gobble-fm/session" // Provides methods for making authenticated API requests. fm := session.New("API_KEY", "SECRET") // Must authenticate a user first. e.g., // Obtain session key from one of the auth methods. fm.SetSessionKey("SESSION_KEY") ``` -------------------------------- ### Instantiate High-Level Last.fm API Clients in Go Source: https://github.com/twoscott/gobble-fm/blob/master/README.md Demonstrates various ways to instantiate high-level Last.fm API clients in Go, ranging from key-only access for unauthenticated calls to full authenticated session management for user-specific interactions. ```Go import "github.com/twoscott/gobble-fm/api" // Basic API client with only the API key. No access to auth methods. fm := api.NewClientKeyOnly("API_KEY") ``` ```Go // Make calls to auth.[getMobileSession|getSession|getToken] methods. fm := api.NewClient("API_KEY", "SECRET") ``` ```Go import "github.com/twoscott/gobble-fm/session" // Authenticate API calls on behalf of a user. fm := session.NewClient("API_KEY", "SECRET") // Must authenticate a user first. e.g., fm.Login("USERNAME", "PASSWORD") // or fm.TokenLogin("AUTHORIZED_TOKEN") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.