feat(spotify): add connection to get token

This commit is contained in:
rick 2021-09-04 13:09:18 +02:00
parent dd9b054b33
commit 1ff4d8a02a
Signed by: Rick
GPG Key ID: 2B593F087240EE99
4 changed files with 26 additions and 1 deletions

View File

@ -1 +1,5 @@
Site pour pouvoir vérifier si un artiste présent sur Spotify possède un compte bandcamp.
Pour configurer le fichier `config.go`:
* ClientID: lid de votre application
* RedirectURI: lien de redirection après lauthentification

View File

@ -1,3 +1,5 @@
package main
var SpotifyAPI = "test"
var SpotifyAPI = ""
var ClientID = ""
var RedirectURI = ""

View File

@ -15,6 +15,17 @@ import (
var MyClient = &http.Client{}
var MyResp = &RespBandcamp{}
func loginSpotify(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
w.Header().Set("Location", "https://accounts.spotify.com/authorize?client_id="+ClientID+"&response_type=token&redirect_uri="+RedirectURI)
w.WriteHeader(http.StatusSeeOther)
go getListPlaylist(r.FormValue("id"))
}
/*
check artist and album
items[x].track.album.name et items[x].track.album.artists[0].name
@ -216,12 +227,18 @@ func getNew(w http.ResponseWriter, r *http.Request) {
MyResp.Notfound = nil
}
func mytest(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, r.RequestURI)
}
func main() {
fileServer := http.FileServer(http.Dir("./static"))
http.Handle("/", fileServer)
http.HandleFunc("/hello", hello)
http.HandleFunc("/back", formHandler)
http.HandleFunc("/refresh", getNew)
http.HandleFunc("/spotify", loginSpotify)
http.HandleFunc("/mytest", mytest)
fmt.Printf("Starting the server…\n")
if err := http.ListenAndServe(":8080", nil); err != nil {

View File

@ -8,6 +8,8 @@
<p>Recherche dans une playlist les artistes se trouvant aussi sur Bandcamp !</p>
<hr />
<a href="/spotify">SE CONNECTER À SPOTIFY ICI</a>
<div>
<form action="/back" method="post">
<label>Saisir lID de la playlist (sans lurl): <input name="id" type="text" required /></label> <br />