Twitch API redirect_mismatch


Twitch API redirect_mismatch

从昨天开始我就忙于Twitch API,做了一个简单的身份验证,重定向uri:

http://localhost:8000/redirect

现在我已经将重定向uri更改为:

http://localhost:8000/connect/twitch

它已经不起作用了。

我已经更改了twitch应用程序面板和请求中的uri,但我仍然得到了"Redirect_Mismatch"。

我做错了什么?

Twitch型号:

class Twitch{
    var $client;
    var $oauth_token;
    public function __construct($token = null)
    {
        $this->client = new GuzzleHttp'Client();
        if($token != null) $this->setOAuthToken($token);
    }
    public function retrieveOAuthToken($code)
    {
        $res = $this->client->post('https://api.twitch.tv/kraken/oauth2/token', [
            'body' => [
                'client_id'     => Config::get('twitch.client_id'),
                'client_secret' => Config::get('twitch.client_secret'),
                'grant_type'    => 'authorization_code',
                'redirect_uri'  => Config::get('twitch.redirect_uri'),
                'code'          => $code
            ],
            'verify'            => false
        ]);
        $result = json_decode($res->getBody());
        $this->oauth_token = $result->access_token;
    }
}

Laravel Twitch配置文件:

return array(
    'client_id' => 'REMOVED',
    'client_secret' => 'REMOVED',
    'redirect_uri' => 'http://localhost:8000/twitch',
);

控制器:

class ConnectController extends 'BaseController {
    public function twitch()
    {
        $twitch = new Twitch();
        $twitch->retrieveOAuthToken(Input::get('code'));
    }
}

Twitch应用程序设置:

Twitch设置

您需要更新您的laravel配置:

return array(
    'client_id' => 'REMOVED',
    'client_secret' => 'REMOVED',
    'redirect_uri' => 'http://localhost:8000/connect/twitch',
);

并且您通过抽动重定向URIhttp://localhost:8000/connect/twitch

如果两个URL中的一个(Laravel或Twitch设置)与另一个不同,则会出现Redirect_Mismatch

您需要在http://localhost:8000/twitch也我不确定Laravel等,但在这种情况下,如果Twitch是这样初始化的,也可以尝试在该页面上添加Twitch类。