Code Monkey home page Code Monkey logo

khan-graphql's Introduction

khan-graphql

Helper methods to get your data from Khan Academy

The problem

Khan Academy shut down their API, leaving you wondering how you could continue to keep your student data in sync between your LMS and Khan Academy.

This isn't...

This is not like the full Khan API. It is not meant for use in user facing environments.

This is..

If you need to get your data from Khan Academy using a backend service, this is for you.

Setup

This is run on Node. It uses axios to log into Khan Academy, and stores the cookies with tough-cookie and axios-cookiejar-support. Once authenticated, you should be able to get various data through the /api/internal/graphql endpoints.

install with

npm i --save khan-graphql

Usage

const { KhanApi } = require("khan-graphql")

const CREDS = {
  identifier: "your coach account",
  password: "your password",
}

const main = async () => {
  let kapi = new KhanApi()

  // always authenticate before retrieving data
  await kapi.authenticate(CREDS.identifier, CREDS.password)

  // now that we are authenticated, we can retrieve data. Let's get the coach data
  // with a helper method
  let data = await kapi
    .getCoach()
    .then((res) => res.data)
    .catch((err) => console.error(err))

  console.log({ data: JSON.stringify(data, null, 2) })

  // or inspect the network calls in Chrome dev tools while on Khan Academy to find
  // another endpoint, and use that. See CONTRIBUTING.md for more details

  let payload = {
    operationName: "getClassList",
    variables: {},
    query:
      "query getClassList {\n  coach {\n    id\n    joined\n    studentLists: coachedStudentLists {\n      name\n      id\n      cacheId\n      key\n      topics {\n        id\n        slug\n        title: translatedTitle\n        iconPath\n        domainSlug\n        learnableContentSummary {\n          countExercises\n          __typename\n        }\n        __typename\n      }\n      autoGenerated\n      countStudents\n      topicTitle\n      classroomDistrictInfo {\n        id\n        isNweaMapSynced\n        __typename\n      }\n      __typename\n    }\n    demoClassProgress {\n      completed\n      selectedTopics {\n        id\n        slug\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n  user {\n    id\n    tosForFormalTeacherStatus\n    schoolAffiliation {\n      id\n      name\n      postalCode\n      location\n      __typename\n    }\n    affiliationCountryCode\n    __typename\n  }\n}\n",
  }
  let customData = await kapi.getGraphQL("/getClassList", payload)

  console.log({ customData })
}

main()

Contributing

I would gladly welcome any contributers to this project. There are many GraphQL endpoints on Khan Academy, with some great data. I would like to get some wrapper around those to make it easier to users to find their students' data.

Please see CONTRIBUTING.md for ideas on how you can help.

khan-graphql's People

Contributors

dependabot[bot] avatar dserejo avatar jb-1980 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

khan-graphql's Issues

Thanks !

Hi Joseph,

Just wanted to thank you for your post in the khanimport repository.

I will study your khan-graphql code and hopefully be able to implement my moodle plugin to retrieve grades using it.

Would you say it would be easier to port to PHP or create a wrapper for a service ? ... I have no idea how to create a service, but I can probably find something useful on youtube :-)

Thanks a lot for your offer to help !
Pierre

Add an endpoint for hacktoberfest

You can follow the guidelines in CONTRIBUTING.md to add another endpoint from Khan Academy.

Just comment on this issue with the endpoint you are adding so no one duplicates an endpoint.

For example, if you were going to add /ProgressByStudent, just comment with something like "I am going to add /ProgressByStudent endpoint".

Import into Moodle

Hi Joseph,

I have now a moodle plugin which gets the grades from students from Khan academy for a specific course. I use the khan_api_server route "ProgressByStudent/:classId" for that.

What I would like to do now is import in Moodle about 500 KA topics and create automatically the moodle courses and the associated gradebooks.

One way I thought about is to create a KA class and use the ProgressByStudent route to get a json, and then extract from the json the info to create the moodle course and gradebook with a script. I am wondering if there are better ways or some project I can reuse. I went through all your repos and I have the impression they are building on the obsolete KA api.

Could you advise me on how you would approach this task ?

Thanks a lot in advance !
Pierre

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.