アプリケーション・プログラミング・インターフェース(API)とは何かを学びます
Use an API in a solution to get information
このレッスンのアクティビティ:
API
API は Application Programming Interface の頭文字をとったものです。
APIとは ウェブサイトやデータベースから情報を取得する方法です。
While cloud storage is usually internal information shared within your solution, APIs allow your solution to access external information from the internet.
Let’s say you are building a solution to help people decide what to wear based on the weather. You could spend lots of time uploading data about the weather into a database, but there are many websites that show the weather.
A better solution would be just to grab data from a weather website and show it to your users through your solution, by using an API.
APIがどのように機能するかについてのわかりやすい解説ビデオがあります。
APIを使うには
- APIを使用しているウェブサイトを見つけましょう。以下はリスト 公開されているAPIの一覧です。
- APIの使い方については、各サイトのドキュメントを読んでみましょう。ほとんどのサイトが例を挙げてくれています。
- サイトによっては、APIを利用する前にAPIキーの登録が必要な場合があります。 APIによっては利用料がかかるものもあるので注意しましょう。
- APIコードをThunkableに組み込みましょう。
コーディング例
以下は、App InventorでAPIを使い始めるための簡単な例です。
Here is a very basic example of using the Google Maps API and the ActivityStarter component to start the Google Maps app from your solution, targeting a specific location. Use this starter template to follow along.
This example tutorial uses an API from OpenWeatherMap.
この簡単なチュートリアルでは、 iTunes APIを使ってアーティスト名を入力したときに曲を再生する方法を紹介します。

このリンクをクリックすると、App Inventorでサイドバーのチュートリアルが開きます。
アクティビティ:フルーツ栄養アプリ
APIを使った果実情報の表示
- App Inventor ギャラリーで Fruit Information プロジェクトへのリンクを開きます。
- App Inventorにアプリをロードします。
- アプリを起動して動作を確認する。
- 以下のJSON文字列の例をチェックして、どのように見えるかを理解しよう。
- 現在、アプリはカロリー情報のみを表示しています。CalorieLabelの下に2つ目のラベルを追加して、返される他の栄養価のいずれかを表示します。
Tip
ベストプラクティスプラクティス 楽しい事実、jsonは何の略?「JavaScript Object Notation」の略。Jsonは1999年に作成され、私たちが毎日使用したり取得したりするデータのほとんどすべてが、何らかの形でjsonを使用する必要がある。もしjsonがなかったら、我々が持っている技術のほとんどすべてが役に立たないだろう。クラウドからのほとんどすべてのデータは、データを受け渡すためにjsonを必要とする。
生徒への質問
友人との間にAPIを作れるか?
友達の誰かが"/hello "と言ったら、あなたは挨拶で応えようとする。これは基本的にAPIだ。ある人が何か(hello)をリクエストしたら、あなたは好きな挨拶で返事を返す。もっと複雑な例があるだろうか?/hug、/triviaQuestion、/story、/weekendSummary。
メンターTipsは、AmeriCorpsから提供されたものです。
以下は、JSON文字列の例です。 FruityViceによって返される JSON 文字列の例です。
{ "genus": "Musa",
"name": "Banana",
"id": 1,
"family": "Musaceae",
"order": "Zingiberales",
"nutritions":
{ "carbohydrates": 22,
"protein": 1,
"fat": 0.2,
"calories": 96,
"sugar": 17.2
}
} 振り返り
Using APIs in your solution can be a very powerful tool, but it is not easy to implement!
必要な情報を得る方法を理解するには、そのサイトのAPIドキュメントを読むのに時間をかける必要があります。
主な用語のおさらい
- Application Programming Interface (API) – a way you can get information from another website or database to use in your solution
追加リソース
