Skip to content

plugins.twitch: switch access token API request to GQL #3341

@bastimeyer

Description

@bastimeyer

As mentioned in #3210, Twitch has begun switching the access token requests on their website to their GQL API a few weeks ago. The transition seems to have been completed by them and no API requests on their old and private api.twitch.tv/api API namespace are being made anymore on their website.

Since the old API is still available, the Twitch plugin is still working fine, but once it gets shut down, which can be any time now, it'll break completely. This means we'll have to switch to the GQL API eventually.

I've opened this thread, so this can be monitored and documented, in case Twitch makes further changes.


There seem to be two GQL request methods available for the access token acquirement and both return the same response:

  1. PlaybackAccessToken with the persistedQuery extension (which is a static sha256 of the request, so their servers can use caching when requests are more complicated - variables don't affect the hash):

    {
      "operationName": "PlaybackAccessToken",
      "variables": {
        "isLive": true,
        "login": "**CHANNELNAME**",
        "isVod": false,
        "vodID": "",
        "playerType": "site"
      },
      "extensions": {
        "persistedQuery": {
          "version": 1,
          "sha256Hash": "0828119ded1c13477966434e15800ff57ddacf13ba1911c129dc2200705b0712"
        }
      }
    }
  2. PlaybackAccessToken_Template

    {
      "operationName": "PlaybackAccessToken_Template",
      "query": "query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) {  streamPlaybackAccessToken(channelName: $login, params: {platform: \"web\", playerBackend: \"mediaplayer\", playerType: $playerType}) @include(if: $isLive) {    value    signature    __typename  }  videoPlaybackAccessToken(id: $vodID, params: {platform: \"web\", playerBackend: \"mediaplayer\", playerType: $playerType}) @include(if: $isVod) {    value    signature    __typename  }}",
      "variables": {
        "isLive": true,
        "login": "**CHANNELNAME**",
        "isVod": false,
        "vodID": "",
        "playerType": "site"
      }
    }

Response:

{
  "data": {
    "streamPlaybackAccessToken": {
      "value": "**access-token-string**", 
      "signature": "**signature-string**",
      "__typename": "PlaybackAccessToken"
    }
  },
  "extensions": {
    "durationMilliseconds": 63,
    "operationName": "PlaybackAccessToken",
    "requestID": "**some-random-ID**"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin issueA Plugin does not work correctly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions