authentication - oriceon/oauth-5-laravel twitter 401 需要授权错误

标签 authentication twitter oauth laravel-5 required

我已经通过使用这个来使用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);
    }
}

到我的 Controller 。 但我更新了我的composer.json。 当我连接 Twitter 时..出现这种类型的错误..

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

我认为创建应用程序时出现问题。请帮助我

最佳答案

检查您的回调网址。Twitter 不提供本地主机测试。请检查 here用于创建应用程序。

关于authentication - oriceon/oauth-5-laravel twitter 401 需要授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34728006/

相关文章:

iOS >> ShareKit >> 推特设置 : How to Get the "bit.ly" Data?

iphone - 如何从 iPhone 应用程序使用 OAuth 到 Twitter?

php - 有哪些 PHP Twitter OAuth 库可用?我应该使用哪一个?

android - 如何使用用户名/密码通过 Devise 和 Android 对用户进行身份验证?

c# - 我应该在哪里存储登录数据?

javascript - 在同一页面登录,检查SESSION,无需重新加载

java - 获得拥有 1000 个关注者的推特用户

python - 使用 OAuth python

java - 如何使用 Twitter4J 进行身份验证?

c# - 将 AppServiceAuthentication 与 signalR 结合使用