1
我正在使用Abraham Twitter API SDK,並且在執行index.php頁面時遇到了一些問題。 在我的config.php頁我的代碼是這樣的無法使用Abraham Twitter API SDK
define('CONSUMER_KEY', 'xxxxxxxxxxxxxxxxxxxxxx');
define('CONSUMER_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('OAUTH_CALLBACK', 'http://example.com/callback.php');
的時候,我在瀏覽器中打開索引文件,它重定向到connect.php 在這裏,如果我點擊Signin with PHP
按鈕,頁面會重定向在這裏redirect.php ,我的問題來了。在redirect.php頁面中,我包含了twitteroauth.php文件。
在我redirect.php文件
/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
case 200:
/* Build authorize URL and redirect user to Twitter. */
$url = $connection->getAuthorizeURL($token);
header('Location: ' . $url);
break;
default:
/* Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';
}
在我twitteroauth.php文件的代碼,構造函數看起來像這樣
function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
$this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
if (!empty($oauth_token) && !empty($oauth_token_secret)) {
$this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
} else {
$this->token = NULL;
}
}
我的錯誤我在瀏覽器中得到的是
Notice: Undefined index: oauth_token in line 80
Could not connect to Twitter. Refresh the page or try again later.
我試過很多方法來解決這個問題。但我失敗了。 請幫助我。 在此先感謝。
我得到完全相同的錯誤。你能否詳細解釋一下你是如何解決錯誤的。 –
@ArchitVerma我編輯了上面的答案。請檢查一下。希望現在更清楚。 –