feat(spotify): get playlist json with it id

This commit is contained in:
rick 2021-08-28 19:20:52 +02:00
parent 5b80cddf1d
commit de43e8981b
Signed by: Rick
GPG key ID: 2B593F087240EE99

View file

@ -4,15 +4,41 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"encoding/json"
) )
var MyClient = &http.Client{}
/*
id de la playlist
*/
func getListPlaylist(id string) {
req, _ := http.NewRequest("GET", "https://api.spotify.com/v1/playlists/"+id+"/tracks", nil)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", SpotifyAPI)
res, err := MyClient.Do(req)
if err != nil {
fmt.Printf("error:", err)
return
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
for token, _ := decoder.Token(); token != nil; token, _ = decoder.Token() {
fmt.Printf("value:", token)
}
}
func formHandler(w http.ResponseWriter, r *http.Request) { func formHandler(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err) fmt.Fprintf(w, "ParseForm() err: %v", err)
return return
} }
fmt.Fprintf(w, "POST request successful") fmt.Fprintf(w, "POST request successful\n")
type_id := r.FormValue("type-id") type_id := r.FormValue("type-id")
id := r.FormValue("id") id := r.FormValue("id")
@ -35,6 +61,9 @@ func index(w http.ResponseWriter, r *http.Request) {
} }
func main() { func main() {
getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
return
fileServer := http.FileServer(http.Dir("./static")) fileServer := http.FileServer(http.Dir("./static"))
http.Handle("/", fileServer) http.Handle("/", fileServer)
http.HandleFunc("/hello", index) http.HandleFunc("/hello", index)