我正在使用Abraham William的TwitterOAuth包构建应用程序。该应用程序运行正常,但我遇到了一个问题。
大约25%尝试安装应用的用户无法这样做。他们在Twitter页面上验证应用程序,然后单击“登录”(在Twitter的网站上)。当它们被引回Callback.php页面时,它会给它们一个空白页面。我无法弄清楚出了什么问题,因为它适用于大多数用户。有什么想法吗?
这是callback.php代码:
<?php
require_once("config_db.php");
session_start();
// Include class & create
require_once("consumer-keys.php");
require_once("twitteroauth/twitteroauth/twitteroauth.php");
// User has selected to DENY access
if(!empty($_GET["denied"])) {
// could re-direct or display cancelled view/template
// we're just echoing out a message
echo "No deal! <a href='login.php'>Try again?</a>";
die();
}
// User has selected to ALLOW access for given token
if($_GET["oauth_token"] == $_SESSION["oauth_token"]) {
// Use generated request tokens (from session) to construct object
$tOAuth = new TwitterOAuth($consumerKey, $consumerSecret, $_SESSION["oauth_token"], $_SESSION["oauth_token_secret"]);
// Retrieve access token from Twitter
$accessToken = $tOAuth->getAccessToken();
//echo "RECEIVED TOKENS<br>";
// Check we have valid response
if(is_numeric($accessToken["user_id"])) {
// Save the access tokens to a DB (we're using a session)
$_SESSION["access_token"] = $accessToken;
//GET CREDENTIALS VIA API
$credentials = $tOAuth->get('account/verify_credentials');
//echo "HAS NUMERIC ID<br>";
//ISAAC ADD DB INFO
$query = "SELECT * FROM `t4i_app`.`users_twitter` WHERE user_id = '".$_SESSION["access_token"]["user_id"]."'";
$rs = mysql_query($query);
if(mysql_num_rows($rs)) {
//update query
//echo "user already exists..need to update";
$query = "UPDATE `t4i_app`.`users_twitter` SET `token` = '".$_SESSION["access_token"]["oauth_token"]."', `secret` = '".$_SESSION["access_token"]["oauth_token_secret"]."', `screen_name` = '".$credentials->screen_name."', `followers` = '".$credentials->followers_count."' WHERE `users_twitter`.`user_id` = '".$_SESSION["access_token"]["user_id"]."';";
mysql_query($query);
} else {
$query = "INSERT INTO `t4i_app`.`users_twitter` (`id` ,`screen_name` ,`token` ,`secret`, `user_id`, `followers`, `referer` ,`last_update` ,`date_registered`) VALUES (NULL, '".$credentials->screen_name."', '".$_SESSION["access_token"]["oauth_token"]."', '".$_SESSION["access_token"]["oauth_token_secret"]."', '".$_SESSION["access_token"]["user_id"]."', '".$credentials->followers_count."', '0', CURRENT_TIMESTAMP , CURRENT_TIMESTAMP);";
mysql_query($query);
}
//echo $query;
//echo mysql_error();
//print_r($_SESSION["access_token"]);
$message = array('status' => 'Test OAuth update. #testoauth');
$test = $tOAuth->post('statuses/update', array('status' => 'I just added the new APPNAME Twitter Application http://bit.ly/sampleurl'));
//echo "POSTED STATUS<br>";
//END ISAAC
// Remove request token session variables
unset($_SESSION["oauth_token"]);
unset($_SESSION["oauth_token_secret"]);
// Redirect to main page
header("location: http://www.mydomain.com/welcome.php");
} else {
//echo "TRYING TO REDIRECT <br>";
header("location: http://www.mydomain.com");
}
}
?>
答案 0 :(得分:0)
if ($_GET["oauth_token"] == $_SESSION["oauth_token"])
你会想要在其他地方放置一个error_log,如果get和session中的oauth_tokens不匹配,你就会失败而没有任何消息。可能是Twitter没有正确回应。
此外,我会在标题调用中将位置大写。我不是100%,当它不是位置时,每个浏览器都会尊重它: