2011-03-16 94 views
0

我正在嘗試使用Twitter Oauth進行登錄。Twitter OAuth問題

的index.php

<?php 
require ("twitteroauth/twitteroauth.php"); 
session_start(); 

// The TwitterOAuth instance 
$twitteroauth = new TwitterOAuth('00000000000000000', '0000000000000000000000000000000'); 

// Requesting authentication tokens, the parameter is the URL we will be redirected to 
$request_token = $twitteroauth->getRequestToken('http://bakasura.in/twitter/twitter_oauth.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']); 
    header('Location: '. $url); 
} 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.'); 
} 

?> 

一旦需要我的授權頁面加載頁面,當我點擊允許它把我帶回到了http://bakasura.in/twitter/twitter_oauth.php

<?php 
require ("twitteroauth/twitteroauth.php"); 

if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){ 

    // We've got everything we need 
    echo "Authorized"; 

} else { 

    // Something's missing, go back to square 1 
    //header('Location: twitter_login.php'); 
    echo "Not Authorized"; 

} 
?> 

,它說「未授權」

你可以在這裏試試http://bakasura.in/twitter/

+0

看起來像會話變量沒有從index.php中設置,傳遞。 –

回答

1

您沒有在第二頁中開始會話。只要你不打電話session_start(),你的會話變量不可用

一些PHP設置已經配置他們的php.ini來自動啓動你的會話,但是當我看着你的服務器設置時,我看到你沒有發送在您的第二頁上爲您的php會話創建一個cookie標頭,所以我很確定您的會話沒有在第二頁上啓動...

+0

是的,這是問題。謝謝。只是確認 - 當我再次回到index.php一旦授權。再次要求我允許。我如何做一次並自動登錄下一次? –

+0

我應該爲特定用戶存儲OAuth組件的Wat憑據嗎? –