skmetaly / laravel-twitch-restful-api by skmetaly

Laravel twitch api
375
8
4
Package Data
Maintainer Username: skmetaly
Maintainer Contact: contact@seblaze.com (Paul Bele)
Package Create Date: 2015-03-31
Package Last Update: 2015-03-31
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:11:31
Package Statistics
Total Downloads: 375
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 8
Total Watchers: 4
Total Forks: 4
Total Open Issues: 1

laravel-twitch-restful-api

Laravel Twittch restful api. An implementation of the twitch restful api V3 provided by Twitch.tv Documentation of the API can be found at Twitch restful api link

Installation

Require the package in composer.json :

"skmetaly/laravel-twitch-restful-api": "dev-master"

In config/app.php add providers

'Skmetaly\TwitchApi\Providers\TwitchApiServiceProvider'

In aliases

'TwitchApi'=>'Skmetaly\TwitchApi\Facades\TwitchApiServiceFacade'

Publish the config

php artisan vendor:publish --force

Create a twitch application ( in your twitch settings page, Connections tab ) Create a client secret Add both client secret, client id to the twitch-api.php config

Change the scopes that the application needs to better suit your needs

Usage

The api provides both non-authenticated and authenticated requests

Authentication

Twitch api uses OAuth 2.0 protocol for authentication.

This API uses the Authorization Code Flow.

First step for authenticating a user is to send him to the twitch authentication URL

   public function authenticate()
   {
       return Redirect::to(TwitchApi::authenticationURL());
   }

Keep in mind that the api uses the config set in twitch-api.redirect_url for redirecting after authentication

After the user accepted the scopes and authorised your app, it will be redirected at the value set in config('twitch-api.redirect_url')

A sample of handling the redirect :

   public function redirect()
   {
       $code = Input::get('code');

       $token = TwitchApi::requestToken($code);
   }

You need to persist both the username and token associated with it to use all of the authenticated requests