我有消费者密钥和秘密。我尝试使用消费者密钥和秘密获取 oauth 请求令牌,但我的错误是我收到错误消息
未捕获的异常“OAuthException”和消息“无效的身份验证/错误请求(收到 404,预期的 HTTP/1.1 20X 或重定向)”
我试过下面的代码来获取请求令牌,但它没有用
$callbackUrl = "http://www.myhost.com/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://www.myhost.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://www.myhost.com/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://www.myhost.com/oauth/token';
$apiUrl = 'http://www.myhost.com/api/rest';
$consumerKey = 'my consumerKey';
$consumerSecret = 'my consumerSecret';
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
}
$authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
if (!isset($_GET['oauth_token']) && !isset($_SESSION['state'])) {
$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
echo $_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
exit;
} else if (isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
$accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
header('Location: ' . $callbackUrl);
exit;
}
print_r($_SESSION);//get this by next page
任何帮助都会很棒!