2015-01-20 41 views
1

我正在嘗試使用Twitter OAuth創建PHP應用程序。在我的代碼中,我使用了twitteroauth庫。我試圖讓授權喜歡在圖書館教程,但我當我試圖使請求記號我得到這個錯誤:TwitterOAuth - 未能驗證oauth簽名和令牌

Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message 'Failed to validate oauth signature and token' in /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php:221 Stack trace: #0 /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/login.php(10): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/request_t...', Array) #1 {main} thrown in /home/kp/domains/konradprzydzial.pl/public_html/tweetupchat/vendor/abraham/twitteroauth/src/TwitterOAuth.php on line 221

我的代碼在這個文件中:

<?php 

require "vendor/autoload.php"; 
require "config.php"; 

use Abraham\TwitterOAuth\TwitterOAuth; 

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); 

$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK)); 

$_SESSION['oauth_token'] = $request_token['oauth_token']; 
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; 

var_dump($request_token['oauth_token']); 
var_dump($request_token['oauth_token_secret']); 

$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token'])); 

echo '<a href="'.$url.'">Zaloguj się</a>'; 

?> 

CONSUMER_KEY和CONSUMER_SECRET是正確的。哪裏有問題?

+0

你甩了消費值對象實例化前右只是爲了仔細檢查它們是正確的?另外,你的電腦的系統時鐘設置是否正確?如果您的約5分鐘不同步,Twitter將失敗。 – patricus 2015-01-20 23:11:24

+0

我甩了它,它是正確的。 我使用共享主機。在Twitter API狀態下,服務器時間比時間提前2分鐘。 – kodipe 2015-01-21 00:03:25

回答

2

我也使用twitter API的abraham/twitteroauth包裝並遇到同樣的問題。

你在這裏的代碼看起來不錯。但是,如果您使用的是由亞伯拉罕在https://twitteroauth.com/redirect.php上給出的文檔,則一種解決方案是刪除圍繞CONSUMER_KEYCONSUMER_SECRETgetenv()函數。

我只能猜測,因爲我不知道在你的config.php文件中使用的代碼,但我希望這會有所幫助。

1

我覺得這是捲曲問題 嘗試檢查,如果他們傳遞正確的參數

abraham\twitteroauth\src\TwitterOAuth.php at line 348

function request($url, $method, $headers, $postfields) 
相關問題