Deezer의 API에 액세스하는 앱을 만들고 있습니다. JSONP 사용 귄터의 팁을 사용Anger2 앱의 Deezer API
,이 같은 Deezer에의 API를 사용하는 경우 :
@Injectable()
export class DeezerService{
constructor(private _jsonp:Jsonp){
}
dzSearch(){
console.log('Testing dzSearch() init');
return this._jsonp.request('https://api.deezer.com/search/artist/?q=deftones&output=jsonp', {method:'Get'})
.subscribe((res) => {
console.log(res);
});
}
}
나는 API 200 OK 응답을하지만, 내 말은 오류를 얻을으로 여전히 작동하지 않습니다
- 예외 : 상태 응답 : URL에 대한 200 OK : https://api.deezer.com/search/artist/?q=deftones&output=json
- catch되지 않은 응답 {_body : 상태 ". JSONP 스크립트 콜백을 호출하지 않았다 주입": (200)를 확인 : 사실, 통계 usText : "확인"을, 헤더 : 헤더 ...}
원래 : 자신의 자바 스크립트 SDK를 사용하여, 나는 사용하여 액세스를 획득했습니다
declare var DZ : any;
@Injectable()
export class DeezerService{
constructor(private _http:Http){
new DZ.init({
appId : 'APPID',
channelUrl : 'http://localhost:4200/src/channel.html'
});
}
dzSearch(){
console.log('Testing dzSearch() init');
DZ.api('/album/12720342/tracks', function(response){
console.log(response.data);
});
}
}
이 작동하지만이 아니다 변수를 전달할 수 없으므로 어떻게 사용하고 싶습니까? Angular2의 Eduonix Course처럼 REST API를 서비스로 사용하고 싶습니다. 함수에서 파이어베이스의 db에 게시 된 것을 테스트하지는 않았지만 성능이 좋지는 않지만 작동 할 것입니다.
내가 바라 보는 뭔가가 있습니까?
그래, 당신은 서버 구성을 변경해야 ;-) 그들의 스크립트는 아마도 문제를 해결하려면 JSONP를 사용하지만 JSONP는 매우 몇 가지 제한 사항이 있습니다. –
JSONP 구현 방법은 무엇입니까? –
https://angular.io/docs/ts/latest/api/http/index/Jsonp-class.html 'HttpModule'과 비슷하게 작동합니다. 예를 들어 SO에 대한 답과 함께 몇 가지 질문이 있습니다. –