Skip to content
Infinite coder edited this page Mar 26, 2023 · 13 revisions

Welcome to the Sketch API wiki!

This repository gets data of sketches on Khan Academy. You can access the data from any other KA sketch. This is similiar to old KA API, just with 1 difference -> it works :D
Before you start using this API, you will need to setup it for your project, see Setup. After you do that, you Import the library and then you can use it.

Setup the API

To setup Sketch API, go here: https://www.khanacademy.org/computer-programming/sketch-api/5783330047180800
Then go to Tips&Thanks and find a thread, that says '>>> Here send your program IDs <<<'. Comment there this:

<YOUR_PROGRAM_ID>

Replace 'YOUR_PROGRAM_ID' with ID of the program, that you will access through the API.
After you do that, you will be able to access the program (it might take up to 10 minutes, before the API starts working, so please be patient).

Importing the library

To import the library, put <script src = "https://cdn.jsdelivr.net/gh/Infinite-Coder-001/Sketch-API@1/main.js"></script> to the <head> of your HTML page. Then, add a <script> tag to the <body>. You can use the API in the <script>. See this example:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Sketch API example</title>
        <script src = "https://cdn.jsdelivr.net/gh/Infinite-Coder-001/Sketch-API@1/main.js"></script>
    </head>
    <body>
        <p id = "demo"></p>
        <script>
            function callback(data) {
                var element = document.getElementById("demo").innerHTML = data.code;
            }
            SketchAPIMain(5234045946740736, callback);
        </script>
    </body>
</html>

This program loads code of program with ID 5234045946740736.

Functions

After you import the library, you will be able to use 4 API function:

  • SketchAPIMain(id, callback); - loads author, code, creation date, flags, sum of votes and sum of forks of a program
  • SketchAPIForks(id, callback); - loads forks of a program
  • SketchAPIFeedbacks(id, callback); - loads feedbacks of a program (limited to 300, without comments)
  • SketchAPIQuestions(id, callback); - loads questions and 1 best answer about a program (limited to 300 questions)

SketchAPIMain

Arguments

  • id - ID of the program, that will be accessed
  • callback - function, that will be called after all data is loaded. The function will be called with an argument -> the API output

Output

An example of API output:

{
    'title': 'My awesome program', 
    'author': {
        'nickname': 'My nickname', 
        'link': 'https://www.khanacademy.org/profile/my-username/', 
    }, 
    'size': {
        'width': 600, 
        'height': 400, 
    }, 
    'link': 'https://www.khanacademy.org/computer-programming/my-awesome-program/1234567890123456', 
    'img': 'https://www.khanacademy.org/computer-programming/my-awesome-program/1234567890123456/5121620907966464.png', 
    'created': '2023-03-10T20:31:20.379627Z', 
    'flags': {
        'flags': null, 
        'flaggedBy': null
    },
    'type': 'webpage', 
    'code': '&lt;DOCTYPE html>\n&lt;html>\n&lt;/html>', 
    'voteCount': 32, 
    'forkCount': 4, 
}

Example code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>New webpage</title>
        <script src = "https://cdn.jsdelivr.net/gh/Infinite-Coder-001/Sketch-API@1/main.js"></script>
    </head>
    <body>
        <p id = "demo"></p>
        <script>
            function cb(data) {
                document.getElementById("demo").innerHTML = JSON.stringify(data);
            }
            SketchAPIMain(5234045946740736, cb);
        </script>
    </body>
</html>

SketchAPIForks

Arguments

  • id - ID of the program, that will be accessed
  • callback - function, that will be called after all data is loaded. The function will be called with an argument -> the API output

Output

An example of API output:

[
    {
        'title': 'Spin-off of \"My awesome program\"', 
        'author': {
            'nickname': 'Spin-off maker', 
            'link': 'https://www.khanacademy.org/profile/kaid_1365431327663050222247'
        }, 
        'link': 'https://www.khanacademy.org/computer-programming/spin-off-of-my-awesome-program/465121649751322312', 
        'img': 'https://www.khanacademy.org/computer-programming/spin-off-of-my-awesome-program/465121649751322312/4740037625561088.png', 
        'voteCount': 3, 
        'forkCount': 0
    },
    {
        'title': 'Spin-off of \"My awesome program\" LOL', 
        'author': {
            'nickname': 'Nobody', 
            'link': 'https://www.khanacademy.org/profile/kaid_1321646432164942347'
        }, 
        'link': 'https://www.khanacademy.org/computer-programming/spin-off-of-my-awesome-program-lol/465121649751322542', 
        'img': 'https://www.khanacademy.org/computer-programming/spin-off-of-my-awesome-program-lol/465121649751322542/4740037625561088.png', 
        'voteCount': 1, 
        'forkCount': 0
    },
], 

Example code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>New webpage</title>
        <script src = "https://cdn.jsdelivr.net/gh/Infinite-Coder-001/Sketch-API@1/main.js"></script>
    </head>
    <body>
        <p id = "demo"></p>
        <script>
            function cb(data) {
                document.getElementById("demo").innerHTML = JSON.stringify(data);
            }
            SketchAPIForks(5234045946740736, cb);
        </script>
    </body>
</html>

SketchAPIFeedbacks

Arguments

  • id - ID of the program, that will be accessed
  • callback - function, that will be called after all data is loaded. The function will be called with an argument -> the API output

Output

An example of API output:

[
    {
        'content': '>>> *SUBSCRIBE TO NEW APIS* <<<\nPost a single period here to subscribe for new APIs and new versions of this API. If you want to completely subscribe to all my programs, go to my subpage: \nhttps://www.khanacademy.org/computer-programming/my-subpage/6251203022864384', 
        'author': {
            'nickname': 'Infinite coder', 
            'link': 'https://www.khanacademy.org/profile/kaid_643015938786727315236008', 
            'avatar': 'https://www.khanacademy.org/images/avatars/svg/blobby-green.svg'
        }, 
        'posted': '2023-03-10T20:52:08.523591Z', 
        'expandKey': 'ag5zfmtoYW4tYWNhZGVteXJACxIIVXNlckRhdGEiHWthaWRfNjQzMDE1OTM4Nzg2NzI3MzE1MjM2MDA4DAsSCEZlZWRiYWNrGICAk_2r4poIDA', 
        'flags': {
            'flags': null, 
            'flaggedBy': null
        }, 
        'replyCount': 2, 
        'voteCount': 7
    }, 
    {
        'content': 'Hello world :)', 
        'author': {
            'nickname': 'Hello', 
            'link': 'https://www.khanacademy.org/profile/kaid_164513165446465165165945', 
            'avatar': 'https://www.khanacademy.org/images/avatars/svg/blobby-green.svg'
        }, 
        'posted': '2020-01-23T19:53:05.523591Z', 
        'expandKey': 'ag5zfmtoYW4tYWNhZGVteXJACxIIVXNlckRhFshlSdocFSjlcoFs2NzI3MzE1MjM2MDA4DAsSCEZlZWRiYWNrGICAk_2r4poIDA', 
        'flags': {
            'flags': null, 
            'flaggedBy': null
        }, 
        'replyCount': 1, 
        'voteCount': 2
    }, 
], 

Example code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>New webpage</title>
        <script src = "https://cdn.jsdelivr.net/gh/Infinite-Coder-001/Sketch-API@1/main.js"></script>
    </head>
    <body>
        <p id = "demo"></p>
        <script>
            function cb(data) {
                document.getElementById("demo").innerHTML = JSON.stringify(data);
            }
            SketchAPIFeedbacks(5234045946740736, cb);
        </script>
    </body>
</html>

SketchAPIQuestions

Arguments

  • id - ID of the program, that will be accessed
  • callback - function, that will be called after all data is loaded. The function will be called with an argument -> the API output

Output

An example of API output:

[
    {
        'content': 'So the Hotlist API gets the programs from the hot list, and the Sketch API gets the program by its id?\nOn another note, are you ever going to unify all of these APIs into one grand post-KA API?',
        'author': {
           'nickname': 'Archbirdplus',
           'link': 'https://www.khanacademy.org/profile/kaid_142152517100107888031317',
           'avatar': 'https://www.khanacademy.org/images/avatars/svg/cs-hopper-jumping.svg'
        },
        'posted': '2023-03-26T06:33:34.271327Z',
        'expandKey': 'ag5zfmtoYW4tYWNhZGVteXJACxIIVXNlckRhdGEiHWthaWRfMTQyMTUyNTE3MTAwMTA3ODg4MDMxMzE3DAsSCEZlZWRiYWNrGICA09iwtt4IDA',
        'flags': {
            'flags': null,
            'flaggedBy': null
        },
        'voteCount': 2,
        'answer': {
            'content': 'Yes, exactly. \nInteresting idea. I'll think about it.',
            'author': {
                'nickname': 'Infinite coder',
                'link': 'https://www.khanacademy.org/profile/kaid_643015938786727315236008',
                'avatar': 'https://www.khanacademy.org/images/avatars/svg/blobby-green.svg'
            },
            'posted': '2023-03-26T09:32:00.382082Z',
            'expandKey': 'ag5zfmtoYW4tYWNhZGVteXJACxIIVXNlckRhdGEiHWthaWRfNjQzMDE1OTM4Nzg2NzI3MzE1MjM2MDA4DAsSCEZlZWRiYWNrGICA07j0xqIKDA',
            'flags': {
                'flags': null,
                'flaggedBy': null
            },
            'voteCount': 1
        }
    }, 
    {
        'content': 'What?',
        'author': {
           'nickname': 'What',
           'link': 'https://www.khanacademy.org/profile/kaid_142152517100107888031318',
           'avatar': 'https://www.khanacademy.org/images/avatars/svg/cs-hopper-jumping.svg'
        },
        'posted': '2012-03-26T06:33:34.271327Z',
        'expandKey': 'ag5zfmtoYW4tYWNhZGVteXJACxIIVXNlcKFfdGEiHWthaWRfMTQyMTUyNTE3MTAwMTA3ODg4MDMxMzE3DAsSCEZlZWRiYWNrGICA09iwtt4IDA',
        'flags': {
            'flags': null,
            'flaggedBy': null
        },
        'voteCount': 1,
        'answer': {
            'content': 'What do you mean? ',
            'author': {
                'nickname': 'idk',
                'link': 'https://www.khanacademy.org/profile/kaid_64301593136527315236008',
                'avatar': 'https://www.khanacademy.org/images/avatars/svg/blobby-green.svg'
            },
            'posted': '2012-03-26T09:32:00.382082Z',
            'expandKey': 'ag5zfmtoYW4tYWNhZGVteXJACxIIVXNlckRhdGEiHWthaWRfNjQzMDE1OTM4Nzg2NzI3MzE1MjM2MDA4DAsSCEZlZWRiYWNrGICA07j0xqIKDA',
            'flags': {
                'flags': null,
                'flaggedBy': null
            },
            'voteCount': 1
        }
    }
], 

Example code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>New webpage</title>
        <script src = "https://cdn.jsdelivr.net/gh/Infinite-Coder-001/Sketch-API@1/main.js"></script>
    </head>
    <body>
        <p id = "demo"></p>
        <script>
            function cb(data) {
                document.getElementById("demo").innerHTML = JSON.stringify(data);
            }
            SketchAPIQuestions(5783330047180800, cb);
        </script>
    </body>
</html>