【问题标题】:oriceon/oauth-5-laravel twitter 401 Authorization Required errororiceon/oauth-5-laravel twitter 401 需要授权错误
【发布时间】:2016-01-18 13:26:38
【问题描述】:

我已经通过这个使用了facebook api。然后我添加了

'Twitter' => [
    'client_id'     => '**************',
    'client_secret' => '***************',
    // No scope - oauth1 doesn't need scope
], 

这些行到config/oauth-5-laravel.php。 然后我添加功能

public function loginWithTwitter(Request $request)
{
    // get data from request
    $token  = $request->get('oauth_token');
    $verify = $request->get('oauth_verifier');

    // get twitter service
    $tw = \OAuth::consumer('Twitter');

    // check if code is valid

    // if code is provided get user data and sign in
    if ( ! is_null($token) && ! is_null($verify))
    {
        // This was a callback request from twitter, get the token
        $token = $tw->requestAccessToken($token, $verify);

        // Send a request with it
        $result = json_decode($tw->request('account/verify_credentials.json'), true);

        $message = 'Your unique Twitter user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        echo $message. "<br/>";

        //Var_dump
        //display whole array.
        dd($result);
    }
    // if not ask for permission first
    else
    {
        // get request token
        $reqToken = $tw->requestRequestToken();

        // get Authorization Uri sending the request token
        $url = $tw->getAuthorizationUri(['oauth_token' => $reqToken->getRequestToken()]);

        // return to twitter login url
        return redirect((string)$url);
    }
}

到我的控制器。 但我更新了我的 composer.json。 当我连接到 twitter.. 这种类型的错误来了..

TokenResponseException in StreamClient.php line 68: Failed to request resource. HTTP Code: HTTP/1.1 401 Authorization Required

我认为在创建应用程序时有问题。帮帮我

【问题讨论】:

    标签: authentication twitter oauth laravel-5 required


    【解决方案1】:

    检查您的回调 url。Twitter 未在 localhost 中提供测试。请检查 here 以了解应用程序的创建。

    【讨论】:

      猜你喜欢
      • 2015-04-28
      • 2019-02-19
      • 2014-11-10
      • 2014-11-21
      • 2012-04-08
      • 2019-12-05
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      相关资源
      最近更新 更多