2011-03-16 25 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

2番目のページでセッションを開始しませんでした。 session_start()を呼び出さない限り、セッション変数は使用できません

一部のPHP設定では、セッションを自動起動するようにphp.iniが設定されていますが、サーバー設定を見ると、あなたの2番目のページであなたのセッションが開始されていないことを確信しています...

+0

それは問題でした。ありがとう。ただ確認する - 私はもう一度index.phpに戻ったときに、それは許可されています。もう一度私に許可を求める。私は一度それをやって、次回に自動ログインすることはできますか? –

+0

OAuthコンポーネントのワットクレデンシャルは、特定のユーザー用に保存する必要がありますか? –