adding spotify what am I listening to api

This commit is contained in:
2025-11-22 11:29:11 +00:00
parent 491c591c3c
commit 8ed08d8f3d
7 changed files with 536 additions and 54 deletions

View File

@@ -1 +1,35 @@
package services
import (
"context"
"log"
"os"
"github.com/zmb3/spotify/v2"
spotifyauth "github.com/zmb3/spotify/v2/auth"
"golang.org/x/oauth2/clientcredentials"
)
func InitSpotify() (*spotify.Client, error) {
ctx := context.Background()
// redirectURI := os.Getenv("SPOTIFY_REDIRECT_URI")
clientID := os.Getenv("SPOTIFY_CLIENT_ID")
clientSecret := os.Getenv("SPOTIFY_CLIENT_SECRET")
config := &clientcredentials.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: spotifyauth.TokenURL,
}
token, err := config.Token(context.Background())
if err != nil {
log.Fatalf("couldn't get token: %v", err)
}
httpClient := spotifyauth.New().Client(ctx, token)
client := spotify.New(httpClient)
return client, nil
}