2017-10-07 38 views
0

我處於OAuth流程的階段,我得到OAuth驗證程序並且必須使用它來獲取永久性令牌,但是我遇到錯誤「無效的oauth_verifier參數」。TwitterOAuth:無效的oauth_verifier參數

// I get a valid oauth verifier 
$oauth_verifier = filter_input(INPUT_GET, "oauth_verifier"); 

// I am able to run var_dump($connection) and the response seems valid 
$connection = new TwitterOAuth(
    $config["consumer_key"], 
    $config["consumer_secret"], 
    $_SESSION["oauth_token"], 
    $_SESSION["oauth_token_secret"] 
); 

// I believe this is where the problem lies, if I try var_dump($token) nothing shows but my original error message 
$token = $connection->oauth(
    "oauth/access_token", [ 
     "oauth_verifier" => $oauth_verifier 
    ] 
); 

$twitter = new TwitterOAuth(
    $config["consumer_key"], 
    $config["consumer_secret"], 
    $token["oauth_token"], 
    $token["oauth_token_secret"] 
); 

完整的錯誤信息是:

Fatal error: Uncaught Abraham\TwitterOAuth\TwitterOAuthException: Invalid request token. in C:\xampp\htdocs\twitteroauth-master\src\TwitterOAuth.php:158 Stack trace: #0 C:\xampp\htdocs\twitter_callback.php(34): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/access_to...', Array) #1 {main} thrown in C:\xampp\htdocs\twitteroauth-master\src\TwitterOAuth.php on line 158 

回答

0

如果你是在本地服務器上運行此然後檢查你的url_callback,它不是在谷歌微小的URL的形式,它必須是「http://localhost:80/file_name」或「http://localhots:8080/file_name」的格式。如果你仍然有這個問題,然後寫你陳述在嘗試catch塊。 例如

try { 
    throw new TwitterOAuthException($result); 
} 
catch(Exception $e) { 

} 

如果您在服務器中運行,儘管總是檢查url_callback不應該出現在谷歌的小URL的形式,因爲新的Twitter的OAuth沒有驗證您的谷歌微小的URL。