Материал из Скретч Вики
API Скретча - интерфейс, который обеспечивает доступ к различным экземплярам данных, в основном удобным для программиста способом. API может быть использован в разных случаях чтобы создавать приложения которые могут отправлять и получать данные с сайта Scratch. В данный момент адрес Scratch API это https://api.scratch.mit.edu.
Биндинги
Если вы не хотите вручную отправлять запросы, есть разные библиотеки, которые упрощают работу с Scratch API.
- Scratchattach - Python
- ScratchClient - Python
- new-scratch3-api - Node.JS
api.scratch.mit.edu
api.scratch.mit.edu - последняя версия API Скретча. Он может быть использован для возврата различных типов данных, касающихся веб-сайта Scratch. Доступ к этому API можно получить по следующему URL-адресу.
https://api.scratch.mit.edu
GET /
Корневая часть интерфейса api предоставляет основную информацию об API и веб-сайте Scratch.
- Примерный запрос
GET https://api.scratch.mit.edu
- Примерный ответ
{ "website":"scratch.mit.edu", "api":"api.scratch.mit.edu", "help":"help@scratch.mit.edu" }
Статус
GET /health
Возвращает статус сайта Скретч.
- Примерный запрос
GET https://api.scratch.mit.edu/health
- Примерный ответ
{ "version":"2d7d8b5e9c7a72cfe15a97ebcc5818ec7380374c", "uptime":11791451, "load":[ 0.0283203125, 0.03515625, 0.04541015625 ], "sql":{ "ssl":true, "started":"2016-03-03T20:54:19.798Z", "min":0, "max":20 } }
Новости
GET /news
Возвращает информацию о разделе «Новости Scratch» на домашней странице.
- Примерный запрос
GET https://api.scratch.mit.edu/news
- Примерный ответ
[ { "id":140458468423, "stamp":"2016-03-04T19:08:01.000Z", "headline":"Scratch Video Update Ep. 14", "url":"https://scratch.mit.edu/discuss/topic/186558/", "image":"https://40.media.tumblr.com/b563e9425dfca8ac53396d997db312ba/tumblr_inline_nwua1f4Chy1szpavb_540.png", "copy":"Want to know what's happening on Scratch? Check out the latest video update!" }, { "id":140391071468, "stamp":"2016-03-03T15:13:27.000Z", "headline":"New Community Blog Post!", "url":"https://scratch.mit.edu/discuss/topic/186359/", "image":"https://36.media.tumblr.com/b8e8bc37f38a135a0f873a6fe7788701/tumblr_inline_nwuak8hOun1szpavb_540.png", "copy":"6 Dance Parties on Scratch To Join Right Now!" }, ... ]
Проекты
GET /projects/count/all
Возвращает номер всех проектов на сайте Скретч.
- Примерный запрос
GET https://api.scratch.mit.edu/projects/count/all
- Примерный ответ
{ "count":13561186 }
Прокси
GET /proxy/featured
Возвращает информацию о проектах, которые на домашней странице сайта.
- Примерный запрос
GET https://api.scratch.mit.edu/proxy/featured
- Примерный ответ
{ "community_newest_projects":[ { "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/10157/8493.png", "title":"Take To The Sky- CC ~OPEN~ remix", "creator":"Sapphire19", "type":"project", "id":101578493, "love_count":0 }, { "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/10157/8191.png", "title":"Untitled", "creator":"Sally_Williams-", "type":"project", "id":101578191, "love_count":0 }, ... ], "community_most_remixed_projects":[ { "title":"Oreo!!!", "type":"project", "remixers_count":429, "love_count":11395, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/2625/7525.png", "creator":"FunnyAnimatorJimTV", "id":26257525 }, ... ], "scratch_design_studio":[ { "gallery_id":1859165, "creator":"NaturalmotionStudios", "remixers_count":0, "gallery_title":"Remix-A-Thon", "love_count":8, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/9805/1641.png", "title":"My Dream House - SDS", "type":"project", "id":98051641 }, ... ], "curator_top_projects":[ { "title":"Colour Dash! ", "creator":"enderbrick", "love_count":30, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/9647/1680.png", "curator_name":"Cirrus-", "type":"project", "id":96471680 }, ... ], "community_featured_studios":[ { "thumbnail_url":"//cdn.scratch.mit.edu/static/site/galleries/thumbnails/139/9754.png", "type":"gallery", "id":1399754, "title":"Robots, Androids, and Artificial Intelligence" }, ... ], "community_most_loved_projects":[ { "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/10022/2418.png", "title":"Instrument Sprites", "creator":"ceebee", "type":"project", "id":100222418, "love_count":104 }, ... ], "community_featured_projects":[ { "thumbnail_url":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/9486/8644.png", "title":"Cavern
GET /proxy/users/<username>/activity
Возвращает информацию о секции «Что я делал(а)» для данного пользователя.
- Примерный запрос
GET https://api.scratch.mit.edu/proxy/users/mres/activity
- Примерный ответ
[ { "obj_id":100736613, "datetime_created":"2016-03-14T12:09:49", "actor":{ "username":"ceebee", "pk":2755634, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/users/avatars/275/5634.png", "admin":true }, "pk":227790976, "message":"\nfavorited\n <a href=\"/projects/100736613/\">I'm A Cat AMV</a>", "extra_data":{ "project_title":"I'm A Cat AMV" }, "type":3 }, { "obj_id":100736613, "datetime_created":"2016-03-14T12:09:49", "actor":{ "username":"ceebee", "pk":2755634, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/users/avatars/275/5634.png", "admin":true }, "pk":227790975, "message":"\nloved\n <a href=\"/projects/100736613/\">I'm A Cat AMV</a>", "extra_data":{ "project_title":"I'm A Cat AMV" }, "type":2 }, { "obj_id":101537695, "datetime_created":"2016-03-14T07:13:36", "actor":{ "username":"ericr", "pk":159, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/users/avatars/0/0159.png", "admin":false }, "pk":227767012, "message":"\nshared the project \n <a href=\"/projects/101537695/\" data-tag=\"object\">a little band</a>", "extra_data":{ "project_title":"a little band" }, "type":10 }, { "obj_id":13182467, "datetime_created":"2016-03-14T04:33:18", "actor":{ "username":"ericr", "pk":159, "thumbnail_url":"//cdn.scratch.mit.edu/static/site/users/avatars/0/0159.png", "admin":false }, "pk":227757062, "message":"\nis now following\n <a href=\"/users/juanneco/\">juanneco</a>", "extra_data":{ "followee_username":"juanneco" }, "type":0 }, ... ]
GET /proxy/users/<username>/activity/count
Был использован для возврата количества непрочитанных сообщений, которые пользователь имеет в данный момент. Теперь он не работает и возвращает ошибку. Тем не менее, GET users/<username>/messages/count до сих пор работает.
https://api.scratch.mit.edu/proxy/users/mres/activity/count
- Примерный запрос
GET { "msg_count":12 }
- Примерный ответ
{{{3}}}
Пользователи
GET /users/<username>
Возвращает информацию о пользователе.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres
- Примерный ответ
{ "id":167, "username":"mres", "history":{ "joined":"2007-03-07T03:50:14.000Z" }, "profile":{ "id":29, "images":{ "90x90":"https://cdn2.scratch.mit.edu/get_image/user/167_90x90.png?v=", "60x60":"https://cdn2.scratch.mit.edu/get_image/user/167_60x60.png?v=", "55x55":"https://cdn2.scratch.mit.edu/get_image/user/167_55x55.png?v=", "50x50":"https://cdn2.scratch.mit.edu/get_image/user/167_50x50.png?v=", "32x32":"https://cdn2.scratch.mit.edu/get_image/user/167_32x32.png?v=" }, "status":"I'm working on new technologies and activities to support the four P's of creative learning: Projects, Passion, Peers, and Play. \n\nKeep on Scratching! =^..^=", "bio":"I'm a professor at the MIT Media Lab. But more important: I'm a member of the Scratch Team! \n\nCheck out my TED talk about Scratch: http://bit.ly/mres-ted-talk", "country":"United States" } }
GET /users/<username>/favorites
Возвращает массив о проектах который пользователь добавил в избранные.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres/favorites
- Примерный ответ
[ { "id":291, "title":"Collision detection example", "description":"My 10-year-old was asking how to have sprite detect when they collide. There are two parts to the answer.\r\rThe first part is to use the sensing block \"touching (other sprite)\", although you could also use \"distance to (other sprite)\"\r\rThe second part is when you want both sprites to detect the collision. The problem I encountered was that one sprite would detect the collision, turn and move away, before the other sprite sensed that they'd collided. This wouldn't be a problem in some circumstances, and I could have solved it by re-ordering when bouncing and moving happened, but instead I used the control block \"broadcast (message)\" to send a bounce message, then both sprites turn when they receive this message.\r\rA simple example that I hope helps someone.", "instructions":"", "history":{ "created":"2007-03-11T21:13:46.000Z", "modified":"2007-03-11T21:13:46.000Z", "shared":"2007-03-11T21:13:46.000Z" }, "stats":{ "views":8567, "loves":17, "favorites":10, "comments":24 } }, { "id":495, "title":"Digital Logic Toolkit", "description":"INSTRUCTIONS\rDrag out and connect your parts any way you want. Click the rotate button to turn parts.\r\rPARTS\rRed and blue power squares.\rLong wire and short wire with yellow inputs.\rAnd gate and Or gate with yellow inputs.\rTriangular inverter with yellow input.\r\rLEARN MORE\rhttp://jjackson.eng.ua.edu/courses/ece380/lectures/\r\rFUTURE DIRECTIONS\rWhat other toolkits could be built in Scratch?", "instructions":"", "history":{ "created":"2007-03-16T03:45:07.000Z", "modified":"2007-03-16T03:45:07.000Z", "shared":"2007-03-16T03:45:07.000Z" }, "stats":{ "views":739, "loves":32, "favorites":25, "comments":15 } }, ... ]
GET /users/<username>/followers
Возвращает список самых поздних подписчиков у пользователя.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres/followers
- Примерный ответ
[ { "id":15833514, "username":"Dylan_Test", "history":{ "joined":"2016-03-15T12:27:56.000Z" }, "profile":{ "id":15833514, "avatar":"1583/3514.png", "status":"", "bio":"I just test things out here\nMy real account ", "country":"Antarctica" } }, { "id":4149226, "username":"ILoveGerbils25", "history":{ "joined":"2014-05-16T23:08:00.000Z" }, "profile":{ "id":4149226, "avatar":"414/9226.png", "status":"I am back\nAT:closed \n\nf4f: sure <33\ncollabs:closed\n\nrequests: closed", "bio":"Raven/She/13/\n\nHi I'm ILoveGerbils25 and I love Sonic, creepypasta, harry potter, pokemon, pusheen,and Splatoon.\nFlockmod:RavenFire66\nMood:Bouncing off the walls ", "country":"United States" } }, ... ]
GET /users/<username>/following
Возвращает список пользователей на которых подписался пользователь.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres/following
- Примерный ответ
[ { "id":1197797, "username":"bubble103", "history":{ "joined":"2012-02-16T06:26:12.000Z" }, "profile":{ "id":1197797, "avatar":"119/7797.png", "status":"✩-- Colour Divide ep2 - 100%\n✩-- Collab with @Driftwood14\n\nMy evil clone >> @bubbIe103", "bio":"Hi there! I'm a shy extrovert.\n------✩-★-✩------\nI love using programming to express myself and my ideas! Scratch is awesome!\n------✩-★-✩------\n", "country":"South Africa" } }, { "id":10707222, "username":"-MarzBarz-", "history":{ "joined":"2015-06-18T23:00:09.000Z" }, "profile":{ "id":10707222, "avatar":"1070/7222.png", "status":"Right now I'm kind of experimenting with my art style so everything's gonna look weird for a while\n*sigh*", "bio":"helloooooooo", "country":"United States" } }, ... ]
GET /users/<username>/messages/count
Возвращает номер непрочитанных сообщений пользователя.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres/messages/count
- Примерный ответ
{ "count":12 }
GET /users/<username>/projects
Возвращает список с информацией о проектах которыми пользователь поделился на сайте Scratch.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres/projects
- Примерный ответ
[ { "id":142, "title":"PlayWithYourFace", "description":"INSTRUCTIONS \r\nClick the Green Flag. Move the mouse over the photos to play with different image effects. Click the Green Flag again to restart. \r\n\r\nHOW I MADE THIS \r\nIn some photos (like the top middle), the mouse position controls the amount of the image effect. In other photos (like the bottom middle), the mouse position controls the rate of change in the image effect. The first case uses the SET EFFECT block; the second cases uses the CHANGE EFFECT block. \r\n\r\nMORE IDEAS\r\nIn these examples, one image effect is applied to each photo. You might want to apply two (or more) image effects to the same photo. For example, make the x-position control one effect and make the y-position control another effect.", "instructions":"", "history":{ "created":"2007-03-07T14:48:22.000Z", "modified":"2007-03-07T14:48:22.000Z", "shared":"2007-03-07T14:48:22.000Z" }, "stats":{ "views":669, "loves":19, "favorites":19, "comments":58 } }, { "id":864, "title":"OceanMusicBox", "description":"This project was inspired by Toshio Iwai, an innovative artist and software designer from Japan. \r\n\r\nINSTRUCTIONS \r\nClick the Green Flag to start. Move the starfish and urchins to change the tune. (You can also use the ones at the bottom of the screen.) Place starfish higher and lower on the screen to play different notes. Move urchins higher and lower on the screen to get different drum sounds. Try changing the SPEED and INSTRUMENT sliders", "instructions":"", "history":{ "created":"2007-03-28T14:01:50.000Z", "modified":"2007-03-28T14:01:50.000Z", "shared":"2007-03-28T14:01:50.000Z" }, "stats":{ "views":239, "loves":21, "favorites":18, "comments":11 } }, ... ]
GET /users/<username>/projects/<project_id>
Возвращает информацию о данном проекте.
- Примерный запрос
GET https://api.scratch.mit.edu/users/mres/projects/142
- Примерный ответ
{ "id":142, "title":"PlayWithYourFace", "description":"INSTRUCTIONS \r\nClick the Green Flag. Move the mouse over the photos to play with different image effects. Click the Green Flag again to restart. \r\n\r\nHOW I MADE THIS \r\nIn some photos (like the top middle), the mouse position controls the amount of the image effect. In other photos (like the bottom middle), the mouse position controls the rate of change in the image effect. The first case uses the SET EFFECT block; the second cases uses the CHANGE EFFECT block. \r\n\r\nMORE IDEAS\r\nIn these examples, one image effect is applied to each photo. You might want to apply two (or more) image effects to the same photo. For example, make the x-position control one effect and make the y-position control another effect.", "instructions":"", "history":{ "created":"2007-03-07T14:48:22.000Z", "modified":"2007-03-07T14:48:22.000Z", "shared":"2007-03-07T14:48:22.000Z" }, "stats":{ "views":669, "loves":19, "favorites":19, "comments":58 } }
site-api (Устарел)
В этой статье или разделе описано то, чего нет в текущей версии Скретч (3.0). Это полезно только с исторической точки зрения. |
site-api - устаревший интерфейс, который стал официально устаревшим 25 октября 2015, как объявил член Команды Скретч, thisandagain.[1] Этот API можно использовать с помощью этого URL:
https://scratch.mit.edu/site-api/
Комментарии
GET /comments/gallery/<studio_id>/
Возвращает комментарии в студии как необработанный HTML.
- Примерный запрос
GET https://scratch.mit.edu/site-api/comments/gallery/5342/
- Примерный ответ
(ответа не доступно)
GET /comments/project/<project_id>/
Возвращает комментарии в проекте как необработанный HTML.
- Примерный запрос
GET https://scratch.mit.edu/site-api/comments/project/142/
- Примерный ответ
(ответа не доступно)
GET /comments/user/<username>/
Возвращает комментарии на профиле данного скретчера как необработанный HTML.
- Примерный запрос
GET https://scratch.mit.edu/site-api/comments/user/mres/
- Примерный ответ
(ответа не доступно)
Заголовки запроса
Здесь указаны заголовки запроса которые могут быть заполнены.
Host: User-Agent: Accept: Accept-Language: Accept-Encoding: Content-Type: X-CSRFToken: X-Requested-With: Referer: Content-Length: Cookie: Connection:
varserver (Удалён)
В этой статье или разделе описано то, чего нет в текущей версии Скретч (3.0). Это полезно только с исторической точки зрения. |
API varserver мог быть использовать чтобы запросить значения облачных переменных в проектах. Этот API может быть использовал по этому URL. Его больше не существует, и теперь все запросы будут возвращать ошибки 404.[2]
https://scratch.mit.edu/varserver/
GET /<project_id>
Возвращал информацию о облачных данных в проекте.
- Примерный запрос
GET https://scratch.mit.edu/varserver/10080213
- Примерный ответ
{ "variables":[ { "name":"☁ Scratch Cat", "value":"2" }, { "name":"☁ Tera", "value":"6" }, { "name":"☁ Gobo", "value":"1" } ], "lists":[ ] }
api/v1(Удалён)
В этой статье или разделе описано то, чего нет в текущей версии Скретч (3.0). Это полезно только с исторической точки зрения. |
23 апреля 2018 года, API v1 был удалён, и теперь он возвращает ошибки HTTP 403.
API v1 был устаревшим интерфейсом который был создан во время создания Scratch 2.0. Его можно было использовать по этому URL.
https://scratch.mit.edu/api/v1/
GET /
Корень API v1 возвращает основную информацию об API.
- Примерный запрос
GET https://scratch.mit.edu/api/v1/
- Примерный ответ
{ "project":{ "list_endpoint":"/api/v1/project/", "schema":"/api/v1/project/schema/" }, "projecttag":{ "list_endpoint":"/api/v1/projecttag/", "schema":"/api/v1/projecttag/schema/" }, "tag":{ "list_endpoint":"/api/v1/tag/", "schema":"/api/v1/tag/schema/" }, "user":{ "list_endpoint":"/api/v1/user/", "schema":"/api/v1/user/schema/" } }
Проекты
GET /project/<project_id>/
Возвращает информацию о проекте и о его создателе.
- Примерный запрос
GET https://scratch.mit.edu/api/v1/project/142/
- Примерный ответ
{ "creator":{ "username":"mres", "userprofile":{ "bio":"I'm a professor at the MIT Media Lab. But more important: I'm a member of the Scratch Team! \n\nCheck out my TED talk about Scratch: http://bit.ly/mres-ted-talk", "country":"United States", "status":"I'm working on new technologies and activities to support the four P's of creative learning: Projects, Peers, Passion, and Play" } }, "datetime_shared":"2007-03-07T14:48:22", "description":"INSTRUCTIONS \r\nClick the Green Flag. Move the mouse over the photos to play with different image effects. Click the Green Flag again to restart. \r\n\r\nHOW I MADE THIS \r\nIn some photos (like the top middle), the mouse position controls the amount of the image effect. In other photos (like the bottom middle), the mouse position controls the rate of change in the image effect. The first case uses the SET EFFECT block; the second cases uses the CHANGE EFFECT block. \r\n\r\nMORE IDEAS\r\nIn these examples, one image effect is applied to each photo. You might want to apply two (or more) image effects to the same photo. For example, make the x-position control one effect and make the y-position control another effect.", "favorite_count":"19", "id":142, "love_count":"19", "resource_uri":"/api/v1/project/142/", "thumbnail":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/0/0142.png", "title":"PlayWithYourFace", "view_count":"669" }
GET /project/set/<project_ids>/
Возвращает информацию о нескольких проектах и их создателей. ID проектов разделены точкой с запятой.
- Примерный запрос
GET https://scratch.mit.edu/api/v1/project/set/142;864/
- Примерный ответ
{ "objects":[ { "creator":{ "username":"mres", "userprofile":{ "bio":"I'm a professor at the MIT Media Lab. But more important: I'm a member of the Scratch Team! \n\nCheck out my TED talk about Scratch: http://bit.ly/mres-ted-talk", "country":"United States", "status":"I'm working on new technologies and activities to support the four P's of creative learning: Projects, Peers, Passion, and Play" } }, "datetime_shared":"2007-03-07T14:48:22", "description":"INSTRUCTIONS \r\nClick the Green Flag. Move the mouse over the photos to play with different image effects. Click the Green Flag again to restart. \r\n\r\nHOW I MADE THIS \r\nIn some photos (like the top middle), the mouse position controls the amount of the image effect. In other photos (like the bottom middle), the mouse position controls the rate of change in the image effect. The first case uses the SET EFFECT block; the second cases uses the CHANGE EFFECT block. \r\n\r\nMORE IDEAS\r\nIn these examples, one image effect is applied to each photo. You might want to apply two (or more) image effects to the same photo. For example, make the x-position control one effect and make the y-position control another effect.", "favorite_count":"19", "id":142, "love_count":"19", "resource_uri":"/api/v1/project/142/", "thumbnail":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/0/0142.png", "title":"PlayWithYourFace", "view_count":"669" }, { "creator":{ "username":"mres", "userprofile":{ "bio":"I'm a professor at the MIT Media Lab. But more important: I'm a member of the Scratch Team! \n\nCheck out my TED talk about Scratch: http://bit.ly/mres-ted-talk", "country":"United States", "status":"I'm working on new technologies and activities to support the four P's of creative learning: Projects, Peers, Passion, and Play" } }, "datetime_shared":"2007-03-28T14:01:50", "description":"This project was inspired by Toshio Iwai, an innovative artist and software designer from Japan. \r\n\r\nINSTRUCTIONS \r\nClick the Green Flag to start. Move the starfish and urchins to change the tune. (You can also use the ones at the bottom of the screen.) Place starfish higher and lower on the screen to play different notes. Move urchins higher and lower on the screen to get different drum sounds. Try changing the SPEED and INSTRUMENT sliders", "favorite_count":"18", "id":864, "love_count":"21", "resource_uri":"/api/v1/project/864/", "thumbnail":"//cdn.scratch.mit.edu/static/site/projects/thumbnails/0/0864.png", "title":"OceanMusicBox", "view_count":"239" } ] }
Пользователи
GET /user/<username>/
Возвращает информацию о пользователе.
- Примерный запрос
GET https://scratch.mit.edu/api/v1/user/mres/
- Примерный ответ
{ "username":"mres", "userprofile":{ "bio":"I'm a professor at the MIT Media Lab. But more important: I'm a member of the Scratch Team! \n\nCheck out my TED talk about Scratch: http://bit.ly/mres-ted-talk", "country":"United States", "status":"I'm working on new technologies and activities to support the four P's of creative learning: Projects, Peers, Passion, and Play" } }
GET /user/set/<usernames>/
Возвращает информацию о данных пользователях. Ники должны разделены точкой с запятой. Значение "userprofile" для каждого объекта был пустым, что делает эту функцию API фактически бесполезной. Следует отметить, что однопользовательская функция остается функциональной.
- Примерный запрос
GET https://scratch.mit.edu/api/v1/user/set/mres;ScratchCat/
- Примерный ответ
{ "objects":[ { "username":"mres", "userprofile":"" }, { "username":"ScratchCat", "userprofile":"" } ] }
Смотрите также
Справочный материал
- ↑ thisandagain. (26/10/2015). «The “site-api” endpoints are all deprecated as of today.» (Конечные точки “site-api” на сегодняшний день устарели.) пост:1552554
- ↑ thisandagain. (22/5/2018). «Yup. That legacy system has been removed.» (Да. Эта система была удалена.) ю:thisandagain/#comments-45728731