【发布时间】:2017-12-29 10:25:37
【问题描述】:
我正在尝试根据以下方式授权 Spotify Web API: https://developer.spotify.com/web-api/authorization-guide/
但是,我收到以下错误:
search.component.ts (18,5):提供的参数与调用目标的任何签名都不匹配
这是我的 search.component 文件:
import { Injectable } from '@angular/core';
import { Http, Headers, Response } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class SpotifyService {
private searchUrl: string;
private redirect_uri:string;
private client_id ='f716e056b5944d9bba2340802a7f88be';
private client_secret = 'acac31590ceb4da38a123253a8c87cc9';
private access_token:string;
private encoded = btoa(this.client_id + ':' + this.client_secret);
constructor(private http: Http) { }
getToken(){
let params = ('grant_type=client_credentials');
let headers = new Headers();
headers.append( 'Authorization', 'Basic ' + this.encoded);
headers.append('Content-Type' , 'application/x-www-form-urlencoded');
return this.http.post('https://accounts.spotify.com/api/token', params , {headers : headers})
.map(res=> res.json());
}
searchMusic(str: string, type = "artist", token: string){
this.searchUrl = 'https://api.spotify.com/v1/search?query=' + str + '&offset=0&limit=20&type=' + type + '&market=US';
let headers = new Headers();
headers.append('Authorization' , 'Bearer ' + token);
return this.http.get(this.searchUrl, {headers: headers})
.map((res: Response) => res.json());
}
}
提前谢谢你们。
【问题讨论】:
-
第 18 行有一个明显的问题需要修复。
-
对于不清楚的问题,我深表歉意。我只是想问一下我的 Spotify Web API 授权解决方案是否正确。你怎么看?
-
最好在这里问:Code Review Stack Exchange