这是我正在使用的教程:
http://net.tutsplus.com/tutorials/php/how-to-authenticate-users-with-twitter-oauth/
在获取访问令牌的最后一步之前,一切似乎都很好,我得到的错误是:
Notice: Undefined index: oauth_token in /var/www/vhosts/opticalexpress.com/httpdocs/facebook/2011/ambassador-referral/classes/twitteroauth.php on line 118
Notice: Undefined index: oauth_token_secret in /var/www/vhosts/opticalexpress.com/httpdocs/facebook/2011/ambassador-referral/classes/twitteroauth.php on line 118
据我所知,一切都应该有效:/
这是代码:
require_once('classes/twitteroauth.php');
session_start();
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('xxxx', 'xxxx');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://www.domain.com/tweet.php');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
if($twitteroauth->http_code==200){
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
echo '<a href="'.$url.'">authorise</a>';
} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
die('Something wrong happened.');
}
if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token'])){
// We've got everything we need
// TwitterOAuth instance, with two new parameters
$twitteroauth = new TwitterOAuth('xxxx', 'xxxx', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// Let's request the access token
$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);
// Save it in a session var
$_SESSION['access_token'] = $access_token;
// Let's get the user's info
//$user_info = $twitteroauth->get('account/verify_credentials');
// Print user's info
//print_r($user_info);
} else {
// Something's missing, go back to square 1
echo 'something missing';
}
我真的疯了,试图让这个工作,任何想法?