Download the PHP package raideer/twitch-api without Composer
On this page you can find all versions of the php package raideer/twitch-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package twitch-api
Twitch API wrapper in PHP
- Installation
- Basic usage
- Authenticated requests
- Resources
Installation
composer require raideer/twitch-api
Usage
Basic, unauthenticated requests.
First we need to create the main Wrapper instance. The constructor takes a Guzzle Client as its only parameter.
Now we can access various Twitch API resources using the wrapper.
You can see all the resources and their methods here:
https://github.com/raideer/twitch-api/blob/master/resources.md
https://github.com/justintv/Twitch-API#index
Note: letter capitalization desn't matter, so $wrapper->CHANNELS->getChannel()
will still work.
Some methods can take an optional array of parameters.
See the official twitch api documentation for the list of parameters.
Authenticated requests
First we need to create an OAuth object, that will contain the necessary information for authenticating our requests.
Read more about authentication here.
Once the user authorizes your application, they will be redirected to your specified URI with a code, that's necessary for obtaining the access token.
Obtaining the Access Token
You can obtain the access token by using the getResponse method. If the request is successful, OAuthResponse object will be returned. It contains the access token, refresh token and registered scopes.
Now you can authorize the Wrapper using the authorize method.
If you authorize the wrapper only by passing the access token, the Wrapper will not be able to check whether the scope you're trying to access actually exists. (Useful if you don't want to make unnecessary requests)
Now you can make authorized requests.
If the request is out of scope, Raideer\TwitchApi\Exceptions\OutOfScopeException
will be thrown.
Throttling (under construction)
If you need, you can enable request throttling.
Time (milliseconds) between requests can be set like so: