Wikipedia API project - would appreciate some help!

Wikipedia API project - would appreciate some help!
0.0 0

#1

Hello! I’m working on the Wikipedia Viewer project, and I can’t seem to get the JSON object from Wikipedia no matter what.

I haven’t decided what data I’m gonna get from the API yet.
For now I’m just testing if getting the JSON data works, first of all, by replacing the text “Result Test” to some JSON data in the Wikipedia query of “Einstein” when a key is submitted in the search bar. But when I check the Chrome console after searching something, it just shows me this error:

Failed to load https://en.wikipedia.org/w/api.php?callback=?https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=soccer&limit=10: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.

I’ve done some research, and what I got from it was that this shouldn’t be an issue if I use jsonp. I set the datatype to jsonp, but it’s still not working. Can someone plz tell me what I did wrong :frowning: Thanks!!!

Link to the Codepen


#2

The URL “https://en.wikipedia.org/w/api.php?callback=?https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=soccer&limit=10” is not right.

I think what you want is "https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=soccer&limit=10&callback=?". I don’t know if you meant to do it but you had 2 URLs in there which Wikipedia didn’t know how to handle.