I know its too late to answer this question.
Yes, you need to get access_token and pass it with your search url to get result. Try to get Spotify access_token as follows,
func callToken() {
let parameters = ["client_id" : "your client id",// u get in developer account in Spotify.
"client_secret" : "ur secret id",
"grant_type" : "client_credentials"]
Alamofire.request("https://accounts.spotify.com/api/token", method: .post, parameters: parameters).responseJSON(completionHandler: {
response in
print(response)
print(response.result)
print(response.result.value)
if let result = response.result.value {
let jsonData = result as! NSDictionary
let token = jsonData.value(forKey: "access_token") as? String
print(token!)
}
})
}
Then save that token and call in ur search url like
search url = "https://api.spotify.com/v1/search?q=Linkin+Park&type=track&limit=5&access_token=\(token)" // pass the token in this string thats it..
Just go through online tutorial in youtube :- https://www.youtube.com/watch?v=KLsP7oThgHU&t=1s for latest version in 2019.
Download full source code with Spotify Integration + search options + default Spotify url and fetch current user's playlist and play in our native iOS App Source:- https://github.com/azeemohd786/Spotify-Demo