无法验证 Twitter Oauth 的临时凭据

我能够获得临时凭证并能够获得 oauth 令牌,但是当我使用返回的令牌来获取用户详细信息时,我无法获取它,因此出现错误。

我正在使用phpleague/oauth1-client包并创建了一个简单的控制器,我在其中关注了他们的Twitter 示例。由此,我收到此错误

League\OAuth1\Client\Credentials\CredentialsException: Received HTTP status code [401] with message "{"errors":[{"code":32,"message":"Could not authenticate you."}]}" when getting temporary credentials. in /var/www/html/PF.Site/Apps/TipsMarketplace/vendor/league/oauth1-client/src/Client/Server/Server.php:418

这是我创建的示例代码。

        $server = new Twitter(array(

            'identifier' => 'my-identifier',

            'secret' => 'my-secret',

            'callback_uri' => "http://localhost:8080/twitter/auth",

        ));


        session_start();

        if (isset($_GET['user'])) {

            $tokenCredentials = unserialize($_SESSION['token_credentials']);


            $user = $server->getUserDetails($tokenCredentials);

            var_dump($user);

        } elseif (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {

            $temporaryCredentials = unserialize($_SESSION['temporary_credentials']);


            $tokenCredentials = $server->getTokenCredentials($temporaryCredentials, $_GET['oauth_token'], $_GET['oauth_verifier']);


            unset($_SESSION['temporary_credentials']);

            $_SESSION['token_credentials'] = serialize($tokenCredentials);

            session_write_close();


            header("Location: http://{$_SERVER['HTTP_HOST']}/twitter/auth?user=user");

            exit;

        } elseif (isset($_GET['denied'])) {

            echo 'Hey! You denied the client access to your Twitter account!';

        }


        $temporaryCredentials = $server->getTemporaryCredentials();


        $_SESSION['temporary_credentials'] = serialize($temporaryCredentials);

        session_write_close();


        $server->authorize($temporaryCredentials);


杨魅力
浏览 159回答 1
1回答

森栏

事实证明,我没有通过推特关注3 条腿的 Oauth ,这也在图书馆的样本中指出。在我上面的代码中,我跳过了其中$server->authorize($temporaryCredentials)将显示 Twitter 的授权页面/登录页面的部分。
打开App,查看更多内容
随时随地看视频慕课网APP