The App Inventor team just released a new component, and its a whopper: the WEB. Before this component, you had to create and deploy server code, using Python, Java, etc, in order for your app to get data from the web. Now you can call APIs directly from your App Inventor blocks! Suddenly, App Inventor programmers have a lot more power to create web-enabled apps that mash data from various sources.
As a first example, check out this App Inventor app that accesses stock quotes from the Yahoo Finance API:
stock quote app in emulator
Designer view for stock quote app
The blocks for stock quote app (click to enlarge)
The app just sets the Web component’s Url property to the base URL of Yahoo Finance, then adds on the stock symbol input by the user in the StockSymbolTextBox.
The call to Web1.Get then invokes the web request. The event Web1.GotText is triggered when the data arrives back from the Yahoo Finance. The data, in this case the stock info in comma-separated form, is returned in the argument responseContent. The app uses the list function listfromcsvrow to get the csv values into list form, then grabs the second item which is the stock’s current value.
The Yahoo Finance API is especially easy to use because it doesn’t require any password or key. You can get different information out, such as the one-day change in the stock, and you can send different parameters in the URL to ask for different data. Check out this site for a nice spec of the Yahoo Finance API.
There are lots of APIs out there, some of which have simple interfaces like Yahoo Finance, and some which require more work. I’ll be exploring more of these in future posts.
This app is a simple one, but if you want to download it to your phone, just scan the following QR code:
Filed under: api communication, how to | Tagged: android, app inventor, web | 44 Comments »