Giter Site home page Giter Site logo

supersonichub1 / twitch-graphql-api Goto Github PK

View Code? Open in Web Editor NEW
37.0 2.0 1.0 4.79 MB

A documentation and schema scraping of Twitch's GraphQL API.

Home Page: https://supersonichub1.github.io/twitch-graphql-api/index.html

License: Other

twitch twitch-api twitch-tv graphql nodejs

twitch-graphql-api's Introduction

Twitch's GraphQL API

A documentation and schema scraping of Twitch's GraphQL API.

NOTE: Due to a certain man's wacky shenanigans, introspection of Twitch's GraphQL API has been disabled, and likely will continue to be disabled for forever. The endpoint, however, is still live, and the schema still usable.

Want a Twitch API that doesn't require a signup, has types and documentation, and makes use of one of the most powerful ways to write an API? Continue reading.

Endpoints

Two are One is currently available:

Pick your poison, I guess; I prefer the former.

Getting Your Client-ID

A Client-ID header is required to use the API, unless you're into errors:

{
    "error": "Bad Request",
    "status": 400,
    "message": "The \"Client-ID\" header is missing from the request."
}

Luckily, Twitch bakes a singular ID into their HTML for some reason: kimne78kx3ncx6brgo4mv6wki5h1ko. If you're afraid that it'll change someday and want a way to scrape it, run this RegEx pattern through their HTML:

/"Client-ID":"(.*)","Content-Type"/

Logging In

This is completely optional, but you can go through Twitch's OAuth handshake and get access to login-only features. See youtube-dl's Twitch extractor if you want an implemented example, as it's decently complex.

Getting the Schema

This repository comes with both GraphQL and JSON representations of the schema dated 3/14/2021, but if you need to download it yourself, e.g. this repository is dead, use get-graphql-schema:

npm install -g get-graphql-schema
# Now get it in GQL...
npx get-graphql-schema https://gql.twitch.tv/gql --header Client-Id=kimne78kx3ncx6brgo4mv6wki5h1ko > schema.graphql
# or JSON!
npx get-graphql-schema https://gql.twitch.tv/gql --header Client-Id=kimne78kx3ncx6brgo4mv6wki5h1ko -j > schema.json

BTW: If the schema on this repository is out-of-date, update it and the docs with pnpm run build and make a pull request.

Reading the Docs

Luckily, Twitch did all the hard work of documenting the API, we just have to make it easliy readable. This repository hosts generated documentation via GitHub Pages. However, if you want to generate and host it yourself, use graphqldoc:

npm install -g graphqldoc
npx graphqldoc -e https://gql.twitch.tv/gql -x \"Client-Id: kimne78kx3ncx6brgo4mv6wki5h1ko\" -o ./docs
# Now host it! I prefer using Python 3's http.server.
python3 -m http.server --directory docs/

BTW: If the schema on this repository is out-of-date, update it and the docs with pnpm run build and make a pull request.

Tools Used

Inspiration & Help

License

This entire repository is licensed under the I Solemny Swear That I Am Up To No Good Public License, a modification of the WTFPL by d0nk for the release of parler-tricks, effectively releasing this body of work into the public domain.

twitch-graphql-api's People

Contributors

supersonichub1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

besuper

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.