skmetaly / laravel-twitch-restful-api

Laravel implementation of the restful api provided by Twitch.tv
MIT License
8 stars 4 forks source link

Class TwitchApi not found #1

Closed UnAfraid closed 8 years ago

UnAfraid commented 8 years ago

Hello, I wanted to use your API since i use laravel but i couldn't find that class.

Also i'd like to have a bit more information, on which method i shall pass client to authenticate. Shall i redirect them to authenticate method?

What should i call for "Redirect URI" i assume the redirect method should be invoked upon their request.

Once the redirection happen should i store some reference so i could check for client's streams for example.

Thanks!

skmetaly commented 8 years ago

Hi,

Thanks for your interest in my package :)

Since i published this package, some things changed in config.app, namely : in 'providers':

        Skmetaly\TwitchApi\Providers\TwitchApiServiceProvider::class

in 'aliases':

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

.

If you are using TwitchApi in a namespaced class ( for example in a controller ) you will have to add :

use TwitchApi;

Please read the authentication method provided by Twitch-API https://github.com/justintv/Twitch-API/blob/master/authentication.md

In order to redirect the user to the authentication page, use :

return Redirect::to(TwitchApi::authenticationURL());

And when the user granted the authentication, twitch will redirect to the setted redirect url ( in config/twitch-api.php ). You will need to request a token by using something similar to :

   public function redirect()
    {
        $code = Input::get('code');
        $token = TwitchApi::requestToken($code);
    }

Also, configure your config/twitch-api.php with your client_id / client_secret of your application

UnAfraid commented 8 years ago

Thanks!

In laravel 5 they changed Redirect and Input now is like:

<?php
namespace App\Http\Controllers;
use TwitchApi;
use Illuminate\Http\Request;

class TwitchController extends Controller {
    public function authenticate(Request $request)
    {
        $code = $request->get('code');
        $token = TwitchApi::requestToken($code);
    }

    public function redirect()
    {
        return redirect(TwitchApi::authenticationURL());
    }
}
skmetaly commented 8 years ago

It doesn't really matter, as redirect() and input() are aliases of Redirect::class and Input::class . check here : https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php#L507 . it uses app() which is an alias for the container, to get the redirect class.

I haven't used Laravel in half a year, so i might be rusty on some aspects :)

UnAfraid commented 8 years ago

Where is TwitchApi class defined, i was looking for it and i couldn't find it, is it some auto generated class or what?

skmetaly commented 8 years ago

If you are using some IDE that will go directly to reference, it will not find it because it's using Laravel Facades. the TwitchAPI is a Laravel Facade of :

vendor/skmetaly/laravel-twitch-restful-api/src/Services/TwitchApiService.php .

That's most probably the class you are searching for :)