[LINUX] How to use the NHK program guide API
Introduction
I want to use a slightly minor API ... So, I summarized the memos when using the NHK program guide API.
I was worried that registration would be a hassle, but it was surprisingly easy to proceed from registration to use.
User registration
- Access the NHK Program Guide API Page.
- Click [Click here if you have not completed user registration] to enter the user registration screen.
- Select the [Create Account] tab, fill in the following items, and click [Create Account].
- username
- Email Address: A registration confirmation email will be sent to this address.
- I accept the terms of use: don't forget to check ...
- You will receive a temporary registration completion email at the above email address in about 5 minutes.
- There is a slight time lag until the confirmation email arrives, so I thought I made a mistake in specifying the email address.
- Go to the URL in the email and change (set) your password to complete the registration.
App registration
The following procedure assumes that you are logged in to the NHK program guide API page.
- Access the NHK Program Guide API page and click [Click here for registered apps].
- Select the My Apps tab and click New App Registration.
- Fill in the following items and click [Create App] to register the app.
- App Name: Enter the app name.
- App URL: This is an optional input item.
- Product: Only the default value [NHK Program Guide API] can be selected ...
Get API key
The following procedure assumes that you are logged in to the NHK program guide API page.
- Access the NHK Program Guide API page and click [Click here for registered apps].
- Select the [My Apps] tab and click the app name you registered earlier.
- You can get the API key by selecting the [Key] tab on the destination page.
API usage example
- Use the
curl
command to get the JSON file of" Currently provided programs "and use the jq
command for the result. It is analyzed and displayed with.
- See also this article for the
curl
and jq
commands.
- Since the strings in JSON are enclosed in double quotes, the
sed
command is used to remove unnecessary double quotes.
nhk_api.sh
#!/bin/bash
json=$(curl -s http://api.nhk.or.jp/v2/pg/now/130/g1.json?key={Your API key})
echo '[Programs currently on air]'
echo 'Channel:'$(echo ${json} | jq '.nowonair_list.g1.present.service.name' | sed 's/\"//g')
echo 'Program name:'$(echo ${json} | jq '.nowonair_list.g1.present.title' | sed 's/\"//g')
echo 'subtitle:'$(echo ${json} | jq '.nowonair_list.g1.present.subtitle' | sed 's/\"//g')
Output result
[Programs currently on air]
Channel: NHK General 1
Program name: News Watch 9 ▽ Japan Post Insurance 12,800 inappropriate sales, the actual situation is ...
Subtitle: ▽ Report card at the beginning of the year? System failure in 53 local governments nationwide ▽ Japan Life Creditors Meeting Request for explanation to the Prime Minister ▽ Gundam Director Tomino Message to young people ▽ Hanyu Kihei to all Japan
important point
- It seems that you can register multiple "apps" on the screen, but "apps" are inseparable from "API keys".
- Therefore, if you click [Register New App] with "App" already registered, the following error will occur.