Making sense of the Wikipedia API

I'm making a app using the map component. When any marker click the user gets a choice to get information about the marker from wikipedia (if there is a wikipage for that marker). In my first version I just used the webviewer, and it worked fine. But it doesn't really look good to just view the web page, so I thought I try to figure out how to use the Wikipedia API instead.
No, I'm a beginner to all this so the concept of API's are to me not quite clear. Anyway, I like to think I've come quite far (for a complete beginner, that is...). My blocks looks like this:


The upper part of the procedure that sets the web component works fine, It takes the information from the markers title to find the right Wikipedia page. And yes, I DO get the right Wikipedia page for every marker. It looks like this:


Now, I got three problems.
#1. The obvious one. It looks like cr*p. Even if you don't understand Swedish you can see that the text is a mess, even if the relevant info IS there, starting with "ÖL 18" är en runsten i Seby..." (you can compare with the wiki page if you want)
I've tried to fix some things with the text blocks, as you can see, but I guess I have to decode it different? Or use html-tags some how? Or is it the input requests in the "set web1 url" that needs to change?
#2 Images. I want the picture from wiki page in my app. How do I do that?
#3. Redirect. Some wiki pages redirects to other locations, on the webviewer it redirects automatic, but now it looks like this:

were "#OMDIRIGERING" means redirect. How do I call the API to redirect? I was thinking about using the text blocks, something like "If contains text #OMDIRIGERING than, bla, bla, bla" but I hope someone knows a simpler solution!

I understand this Topic is more about the Wikipedia API than Appinventor, but since I'm a beginner and not familiar with any other programming language everything I'm trying to find out about Wiki's API and API's in general is very hard to understand.
Hope someone can help me with this! / Thanks

I can understand the desire to do your own thing, but it will take a lot of work to deconstruct a wikipedia page then put it back together again....

Did you use the mobile-html view? This seems perfect for what you want to do....

https://en.wikipedia.org/api/rest_v1/page/mobile-html/App_Inventor_for_Android

This discussion (although it is also about amazon api) provides links showing one way to use the Wipedia API with App Inventor Error on Amazon api - #2 by SteveJG and several examples. Possibly it will help'

WikiipediaSearchResults_1_0.aia (104.0 KB)

This is not hard.

You seem to have missed the lessons on lists, tables, table lookup, and dictionaries.
See FAQ Section: JSON and Dictionaries

I didn't use the mobile view. It looks much better, though not as good as I intended. If I can't manage the API I'll go with that (for version one, until my skills improve...), anyway - thanks!

SteveJG and ABG: Thanks, I will take look.

Hello SteveJG, it's a great app, great code. It has helped me a lot to understand JSON code and lists. I am trying to leave the search on Wikipedia in text format, as in the image1, I have used the blocks that you expose (code image), but I cannot get the text of the search on Wikipedia, what block would be missing to complete the search? Thanks a lot

@Javivi

That is probably no longer possible. I wrote the 'text' version in December 2017 (the images you post that show a plain text api response); by 2018 Wikipedia changed their api to refer to an html in their json and xml response options. I rewrote the code (see post #7) to parse the json and point to their url for the item. The text response you see in your circled box,
wikepediaURL
is no longer possible with their present api as they replaced it with a url.

Edit: Actually on reflection, I believe the text string was captured in the levelTwoList but the api now renders that item as

wikepediaURL2 an empty string

There may be a way to get a text response; so far I have not found it. :cry:

You might experiment with the output parameter (MediaWiki API help - Wikipedia) and examine what the Get captures. I tried several and all I get it the url link.

1 Like

@Javivi Here is a way to produce plain text rather than an url result using the Wikipedia api

I hope it helps.