2011-07-01 101 views
0

我正在使用Abraham William的TwitterOAuth軟件包構建應用程序。該應用程序工作正常,除了我遇到一個問題。Abraham Williams Twitter oAuth PHP回調問題

約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

[啓用] [錯誤日誌](http://php.net/manual/en/errorfunc.configuration.php)* *爲您的PHP應用程序。空白頁面是某處發生致命錯誤的標誌。因此,如果您啓用了錯誤日誌記錄,則會發現記錄了這些錯誤。這將幫助你找出偶爾發生的事情。如果您還記錄了警告和通知,您甚至可能會發現更多的錯誤來幫助您獲得腳本的工作。 – hakre

+0

謝謝你的提示。我確實啓用了錯誤日誌記錄,並且我一直在監視日誌但沒有相關的錯誤。任何其他想法? –

回答

0
if ($_GET["oauth_token"] == $_SESSION["oauth_token"]) 
  • 你要放一個error_log中的其他人對於這一點,你沒有沒有任何消息,如果oauth_tokens在get和session不匹配。這可能是Twitter沒有正確迴應。

  • 另外,我會在頭文件中調用大寫位置。我不是100%,每個瀏覽器將履行它時,它不是地點: