I'm getting an error with a reactive extension (rx) Observable subscribe operator and not seeing why. It seems that the same code in tutorials I've done works fine, but for some reason I'm getting an error working with an actual API.
getChannelVideos(channelId: string): Observable<any>{
var url = `${this._baseUrl}/channels/${channelId}/videos`;
return this._jsonp.get(url).map(response => response.json());
}
// url https://api.twitch.tv/kraken/channels/khaldor/videos
In my component, I call that service function in ngOnInit
.
ngOnInit(){
this._twitchService.getChannelVideos('khaldor')
.subscribe(response => console.log(response));
}
In the network tab, I get a 200 response with a JSON object
{"_total":2,
"_links":{...},
"videos": {...}
}
In the console, I get an error videos:1 Uncaught SyntaxError: Unexpected token :
which references the first semi-colon in the returned JSON response.
I've tried removing the .map
in the service, but I get the same error when applying .subscribe()
to the Observable object in the component.