Appearance
TwitchApiService
php
class Zairakai\LaravelTwitch\Services\TwitchApiServiceSource: src/Services/TwitchApiService.php
Constants
| Name | Value | Description |
|---|---|---|
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(): stringGet app access token for client credentials flow. Cached for 1 hour to avoid excessive token requests.
getGame()
php
public function getGame(string $gameId): arrayGet game information by ID (with caching).
Returns array<string, mixed>|null
getStream()
php
public function getStream(string $userId): arrayGet stream information by user ID (with caching).
Returns array<string, mixed>|null
getUser()
php
public function getUser(int|string $identifier): arrayGet user information by username or ID (with caching).
Returns array<string, mixed>|null
setAccessToken()
php
public function setAccessToken(string $token): selfSet 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 = []): arrayMake 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 = []): arrayMake 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 = []): stringMake 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 = []): arrayMake an authenticated API request.
Returns array<string, mixed>