Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

access token 415

access token 415

Plan

Free/Premium

Country

 

Device

(iPhone 8, Samsung Galaxy 9, Macbook Pro late 2016)

Operating System

(iOS 10, Android Oreo, Windows 10,etc.)

 

My Question or Issue

 

i try to get access token from a service in angular 17 application
the same code works if placed in app.component but if setted in a service return the 415 error

 

getToken(): void {
    const headers = new HttpHeaders({
      Authorization: 'Basic ' + btoa(`${this.clientId}:${this.clientSecret}`),
      'Content-Type': 'application/x-www-form-urlencoded',
    });

    const body = new URLSearchParams();
    body.set('grant_type', 'client_credentials');

    this.http
      .post<Token>(this.tokenUrl, body.toString(), { headers })
      .subscribe({
        next: (t: Token) => (data: any) => {
          this.token = t.access_token;
          this.token = data.access_token;
        },
        error: (error) => console.error('Error fetching access token:', error),
      });
  }

 

Reply
3 Replies

the code above has a mistake

please see this (with always 415 error)

getToken(): void {
    const headers = new HttpHeaders({
      Authorization: 'Basic ' + btoa(`${this.clientId}:${this.clientSecret}`),
      'Content-Type': 'application/x-www-form-urlencoded',
    });

    const body = new URLSearchParams();
    body.set('grant_type', 'client_credentials');

    this.http
      .post<Token>(this.tokenUrl, body.toString(), { headers })
      .subscribe({
        next: (t: Token) => {
          this.token = t.access_token;
        },
        error: (error) => console.error('Error fetching access token:', error),
      });
  }

I see that 'Quotation' marks are missing around Authorization.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

I try that but with same errore

Tks for help

Suggested posts