NAME
Net::Twitch::API - Helper methods for Twitch's "new" helix API
SYNOPSIS
use Net::Twitch::API;
my $api = Net::Twitch::API->new(
access_token => 'your-token',
client_id => 'your-id',
debug => 1,
);
my $response = $api->getUsers({ login => 'twitchdev' });
DESCRIPTION
This module provides methods and helper wrappers to work with what Twitch "new" helix API. The new API is prefixed with the helix codename/namespace and the successor of the old kraken API which was decommissioned on February 28, 2022. A little more about that on dev.twitch.tv "legacy v5 integrations" migration guide.
Using this module to issue requests against Twitch's API requires you to register your "application" with Twitch first. Authentication then is either faciliated via OAuth 2.0 or OpenID Connect. We here use the OAuth2 scheme.
Twitch uses several types of auth tokens. Use the twitch CLI client to obtain an "app access token". This type of token enables your app to make secure API requests that are not on behalf of a specific user. App access tokens are meant only for server-to-server API requests and should never be included in client code. Normally, such tokens would be programmatically refreshed at arbitrary intervals according to OAuth2 RFC but on Twitch app access tokens are valid for 60 days and cannot be refreshed.
This module uses Yosukebe's excellent WebService::Simple as base calss. So look there for addditonal documentation. You might also note that Yosukebe himself recently switched over to the newer WebService::Client, but that's a Moo based module.
FUNCTIONS
new()
Calls underlying WebService::Simple's new(), with additional checks and defaults for Twitch.
You must provide your access_token and client_id.
If debug is set, the request URL will be dumped via warn() on get or post method calls.
WebService::Simple by default croaks (dies) on a failed request. This module returns on error and success with a reference to a hash containing received data. The hash key error is defined on unsuccessful requests.
If you supply a Cache object to new(), each request is prepended by a cache look-up. Refer to WebService::Simple for an example.
getUsers()
Expects a hashref. Users can be looked up either via their login name (username / nickname) or via their numeric user id. Twitch allows to ask for multiple names in one request. Current limit is 100. Use an arrayref of values instead of a scalar then.
Returns a hashref with hash-key data holding a reference to an array of users.
EXPORT
Nothing by default.
CAVEATS
Note that Net::Twitch::API is a WIP module. Things are incomplete or may change without notice.
SEE ALSO
Official Twitch documents:
Getting Started walks you through basic setup of your app and helps with a first request.
Reference gives an overview of core principles like pagination and rate limits.
Reference si the canonical Twitch API endpoints reference. A little more an be found in the api docs for the twitch-cli command-line client.
Within the Perl universe, Twitch related code can be found in outdated modules App::Twitch and Net::Twitch::Oauth2 and Corion's non-API helper module WWW::Twitch.
AUTHOR
Clipland GmbH https://www.clipland.com/
This module was developed for "Sendung verpasst?" video search engine MediathekSuche.de.
COPYRIGHT & LICENSE
Copyright 2022 Clipland GmbH. All rights reserved.
This library is free software, dual-licensed under GPLv3/AL2. You can redistribute it and/or modify it under the same terms as Perl itself.