Skip to content

TwitchApiService ​

php
class Zairakai\LaravelTwitch\Services\TwitchApiService

Source: src/Services/TwitchApiService.php

Constants ​

NameValueDescription
TWITCH_API_DOC_DATE'2026-02-04'Date of the last Twitch API reference check. Use this to detect when the upstream docs have changed.

Methods ​

__construct() ​

php
public function __construct(string $clientId, string $clientSecret)

getAppAccessToken() ​

php
public function getAppAccessToken(): string

Get app access token for client credentials flow. Cached for 1 hour to avoid excessive token requests.

getGame() ​

php
public function getGame(string $gameId): array

Get game information by ID (with caching).

Returns array<string, mixed>|null

getStream() ​

php
public function getStream(string $userId): array

Get stream information by user ID (with caching).

Returns array<string, mixed>|null

getUser() ​

php
public function getUser(int|string $identifier): array

Get user information by username or ID (with caching).

Returns array<string, mixed>|null

setAccessToken() ​

php
public function setAccessToken(string $token): self

Set the user access token for authenticated requests. Call this before making requests that require user context.

makeQueryAndBodyRequest() ​

php
protected function makeQueryAndBodyRequest(string $method, string $endpoint, array $queryParams, array $bodyParams = []): array

Make an authenticated API request that needs BOTH query string and JSON body params at once - Send Whisper is the one endpoint in the package that does (from_user_id/to_user_id as query, message as body), confirmed against Twitch's own docs (2026-08-27). Every other request shape needs at most one or the other, hence makeRequest()/ makeQueryRequest() only ever populate a single Guzzle option key.

Returns array<string, mixed>

makeQueryRequest() ​

php
protected function makeQueryRequest(string $method, string $endpoint, array $params = []): array

Make an authenticated API request whose params always belong in the query string, regardless of HTTP method - a handful of Twitch endpoints take their identifying parameters (broadcaster_id, moderator_id, message_id, ...) as query params even on a PUT/PATCH/DELETE, e.g. Pin/Update Pinned/Unpin Chat Message, Update User Chat Color. makeRequest() only ever sends query params for GET/DELETE - calling it for one of these would silently put the params in the JSON body instead, and Twitch would reject the request with a 400 ("required query parameter missing").

Returns array<string, mixed>

makeRawRequest() ​

php
protected function makeRawRequest(string $method, string $endpoint, array $params = []): string

Make an authenticated API request and return the raw response body as a string. Use this for endpoints that return non-JSON content (e.g. iCalendar).

makeRequest() ​

php
protected function makeRequest(string $method, string $endpoint, array $params = []): array

Make an authenticated API request.

Returns array<string, mixed>

Documentation of 4.1.4 , built from a03e949 on 4.1.4 by pipeline #2949087255 on 2026-10-11.