无法验证 Twitter Oauth 的临时凭据
Could not authenticate temporary credentials for Twitter Oauth
我能够获得临时凭证并能够获得 oauth 令牌,但是当我使用返回的令牌来获取用户详细信息时,我无法获取它,因此出现错误。
我正在使用 thephpleague/oauth1-client package and created a simple controller where I followed their Twitter Sample。由此,我得到了这个错误
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);
原来我没有跟从图书馆的3-legged Oauth by twitter which is also indicated in the sample。
在我上面的代码中,我跳过了 $server->authorize($temporaryCredentials)
,其中它将显示 Twitter 的授权 Page/Login 页面。
我能够获得临时凭证并能够获得 oauth 令牌,但是当我使用返回的令牌来获取用户详细信息时,我无法获取它,因此出现错误。
我正在使用 thephpleague/oauth1-client package and created a simple controller where I followed their Twitter Sample。由此,我得到了这个错误
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);
原来我没有跟从图书馆的3-legged Oauth by twitter which is also indicated in the sample。
在我上面的代码中,我跳过了 $server->authorize($temporaryCredentials)
,其中它将显示 Twitter 的授权 Page/Login 页面。