2011-03-16 101 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凭据吗? –