Search code examples
khan-academy

How can I get all the exercises for a topic (e.g., math) and all its subtopics from the khanacademy api?


Khan Academy's API Explorer has an exercises section that mentions filtering by tags, but the url with math tag applied returns nothing.

The generic exercise objects don't contain the topic they're in. My guess is that there's an id to join on somewhere in the topictree/exercises json objects, but I don't know an efficient way to find it.

Here are the raw exercises json and raw topictree json (note, the second one is huge, and contains many topics other than math).


Solution

  • I don't think there is a nice way to return exercises from just a subtree of the topictree (e.g. just math). Tags are a different concept, and there isn't a tag common to everything in math. Probably your best bet is to load the full topictree with just Exercises (and Topics) and work from there:

    http://www.khanacademy.org/api/v1/topictree?kind=Exercise

    If you need to reference this structure repeatedly, it probably makes sense to download and filter it ahead of time, and maybe re-fetch it from time to time to account for changes to Khan Academy content. But it depends on your exact use case.

    Generally, any content item can be referenced by content_id (sometimes just called id) or by slug, but unfortunately, the naming and usage aren't consistent everywhere.