0

Using the khan academy API, I would like to retrieve a list of all math topics and sub-topics for a certain grade (and related video ids), similar to what you can see here - https://www.khanacademy.org/math/cc-seventh-grade-math

Ideally, I would like to pass the grade (7th) and subject (math) as a parameter in an API call to do this? Is this possible?

Looking at the full topic tree, 'domain-slug' appears to be the closest thing to 'subject' in the way that I'm using the word, but it doesn't appear to be set consistently. I also don't see a dedicated field for grade.

How would you go about achieving this? Any advice would be most appreciated. Thanks.

willcom
  • 15
  • 3

1 Answers1

0

I don't use the topic tree API call - it returns about 50 MB of data. I rather traverse the nodes of the tree individually using the API call "http://www.khanacademy.org/api/v1/topic/%s" where %s is the "node_slug" field, starting with a "node_slug" of "root".

From there you use the "children" and "child_data" entries to traverse the sub-nodes. "children" has the details and "child_data" basically just the order in which they appear.

For each node, there are two important fields to look at, "kind" and "render_type".

"kind" can have the values:

  • "Topic"
  • "Video"
  • "Exercise"
  • "Article"
  • "Scratchpad"
  • "Separator"

"render_type" can have the values:

  • "Root"
  • "Domain"
  • "Subject"
  • "Topic"
  • "Tutorial"
  • "UncuratedTutorial"

So, from "root" you iterate through the child nodes looking for nodes with "render_type" = "Domain". That will give you stuff like "math", "science", etc. Now you can use the "math" node to iterate through the subjects under it, looking for "render_type" = "Subject". Among those you will find 7th Grade, etc.

Note: Both domain and subject nodes have "kind" = "Topic", so you should make sure you check for these and then use the "render_type" to find the domain or subject distinction.

What I also do is to cache the JSON responses so that the application doesn't have to reload them from the website. I have an option to refresh them from the website when needed.

Then you can use the subject node to further iterate through its children for the videos, exercises, articles, etc.

Jannie Gerber
  • 659
  • 1
  • 7
  • 15
  • Many thanks @Jannie ! I'm finally getting somewhere because of this. Perhaps it is a limitation of the platform I'm using to build my app but I can't filter at the top node level. So if I do http://www.khanacademy.org/api/v1/topic/s%, I can't filter the results by render_type. I can only filter 'children' records and render_type does not appear to exist for children or child records - only for the current top-level topic. I'm probably looking at it wrong. – willcom Jan 24 '17 at 21:21
  • Okay, so I have this working, sort of. Just to try it out I created 4 drop-down lists (DDLs). DDL1 displays all node_slugs for the topic 'math'. DDL2 displays all node_slugs for the topic selected in DDL1, DDL3 shows node_slugs for the one selected in DDL2. All these use the API call http://www.khanacademy.org/api/v1/topic/s%. Finally, DDL4 uses the get video API to display a list of video ids. My issue now is can I rely on topics being 3-levels deep? I'm not using render_type in any of these due to the issue I mentioned above. Would it let me skip a step or two to get to the videos? – willcom Jan 24 '17 at 22:03
  • I wouldn't rely on topics being 3 levels deep. In stead of using dropdowns, I use a tree-view which I populate as I open the topic sub-nodes. So it would still work if they have videos as well as sub-topics under a topic (which they don't currently have). – Jannie Gerber Jan 29 '17 at 20:32
  • Thanks. I got it working in the end. I didn't use dropdowns in the end. I just used cascading lists and it's working quite well. I'm also toying with the idea of caching the values, once I figure out a way to do it :-). Many thanks for setting me on the right path on this. – willcom Jan 30 '17 at 22:10