我正在尝试为Web应用程序实现Twitter Oauth登录,但是登录脚本返回错误消息; “通知:未定义的变量:第23行的C:\ xampp \ htdocs \ startNg \ Learnphp \ hnp1 \ twindex.php中的连接
致命错误:未捕获错误:在C:\ xampp \ htdocs \ startNg \ Learnphp \ hnp1 \ twindex.php:23中调用对成员函数oauth()的null:C中引发的堆栈跟踪:#0 {main}: \ xampp \ htdocs \ startNg \ Learnphp \ hnp1 \ twindex.php第23行“
该消息说我的连接变量未定义,但在代码中已明确定义
require 'config.php';
require 'Twitterloginphp/autoload.php';
//use twitter helper
use Abraham\TwitterOAuth\TwitterOAuth;
if (isset($_SESSION['twitter_acces_token']) && $_SESSION['twitter_acces_token']) {//we have access token
}
elseif (isset($_GET['oauth_verifier']) && ($_GET['oauth_token']) && isset($_SESSION['oauth_token']) && $_GET['oauth_token']== $_SESSION['oauth_token'] ) { //coming from twitter callback url
$connection= new TwitterOAuth( CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token=$connection->oauth('oauth/access_token', array('oauth_callback'=> $_GET['oauth_verifier']));
$_SESSION['twitter_acces_token']=$access_token;
$isLoggedIn=true;
}
else { // not been authorised with our app, show login button
$twitter=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'];
$isLoggedIn= false;
请问我该如何解决?