我能够获得临时凭证并能够获得 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);
森栏