我正在使用 Abraham Twitter API SDK,在执行 index.php 页面时遇到了一些问题。在我的 config.php 页面中,我的代码是这样的
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.
我尝试了很多方法来解决这个问题。但我失败了。请帮助我。提前致谢。