Post here any issues with the API or feature requests
BillyAB
Posts: 2 Joined: Sat Jan 10, 2015 4:41 pm
Location: UK
Contact:
Post
by BillyAB » Sat Jan 10, 2015 4:49 pm
Hi All,
I was wondering if someone could help me with this.
I have this JQuery code
Code: Select all
$.getJSON("http://webservice.fanart.tv/v3/movies/" + movieID + "?api_key=4e6175137822b938951bee8a411a251d&callback=?", function (json) {
console.log(json);
var thumbURL = json[0].moviethumb[0].url;
where_to_show_poster_selector.append('<img src="' + thumbURL + '" title="' + data.results[0].title + '" />');
})
When this is run, in my chrome console i get " Uncaught SyntaxError: Unexpected token"
See Image in Spoiler
Thanks in Advanced
BillyAB
Last edited by
BillyAB on Sun Jan 11, 2015 2:02 pm, edited 1 time in total.
Kode
Site Admin
Posts: 353 Joined: Wed Dec 18, 2013 11:34 am
Post
by Kode » Sat Jan 10, 2015 6:24 pm
Not 100% sure, it's possibly because the request is cross domain so it's expecting JSONP rather than JSON
*edit* I see in your request now &callback=? so it's defintitely expecting JSONP, the API doesn't currently support JSONP, a work around is to call the api on the server side in a script and request that local script in your JSON request.
BillyAB
Posts: 2 Joined: Sat Jan 10, 2015 4:41 pm
Location: UK
Contact:
Post
by BillyAB » Sun Jan 11, 2015 1:55 pm
Hi Thanks, I thought that was the issue.
We needed to make the move to using PHP for the requests over JS so i'll share my function for anyone else having an issue.
Code: Select all
function GetMovieThumb($MovieID)
{
$URL = "http://webservice.fanart.tv/v3/movies/".$MovieID."?api_key=4e6175137822b938951bee8a411a251d";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$FArt = curl_exec($ch);
curl_close($ch);
$FArt = json_decode($FArt, TRUE
);
//var_dump($json);
$moviethumb = $FArt["moviethumb"];
$moviethumb = $moviethumb[0];
$moviethumb = $moviethumb["url"];
return $moviethumb;
}
Cheers Billy