Answer the question
In order to leave comments, you need to log in
How to pass an authorization key in a get request?
I ask for help, how to pass the authorization key in the get request?
The key is valid as there is a result on the console spotify test page.
I make a service based on Spotify
Music search is carried out on such a request (from the documentation)
curl -X "GET" " https://api.spotify.com/v1/search?q=armin&type=tra... " -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer BQASa02dtw1lTM2wL-pslHAsf9ZRdMWFpfLmHmnTGXpmGWJzBN-_ALzbpweBl30sZvooeIvxgRRkYeJV7UY"
import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {HttpHeaders} from '@angular/common/http';
getMusic(music, type, limit, offset, key) {
console.log(key.token);//ключ авторизации, можно задать и явно строкой, суть не меняется
let headers = new HttpHeaders()
.append('Content-Type', 'application/json') // через метод set - результат такой же
.append('Authorization', `Bearer ${key.token}`);
return this.http.get(`https://api.spotify.com/v1/search?q=${music}&type=${type}&limit=${limit}&offset=${offset}`, {header: headers});
Answer the question
In order to leave comments, you need to log in
{header: headers}
https://angular.io/guide/http#adding-headersheaders: headers
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question