2011-06-10 109 views
1

我認爲我已經正確實施了twitter oauth,但每次用戶點擊通過Twitter登錄我的網站時,他都被重定向到https://twitter.com/oauth/authenticate?oauth_token=XYZ在那裏他被提示再次授權我的應用Twitter OAuth不斷重定向到https://twitter.com/oauth/authenticate?oauth_token=XYZ

我的源代碼是基於: http://www.9lessons.info/2011/02/login-with-facebook-and-twitter.html這本身似乎基於https://github.com/abraham/twitteroauth/tree/master/twitteroauth

$twitteroauth = new TwitterOAuth(TWITTER_KEY, TWITTER_SECRET); 
// Requesting authentication tokens, the parameter is the URL we will be redirected to 
$request_token = $twitteroauth->getRequestToken($site_url.'getTwitterData.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('The Twitter service is currently not responding. Please try again later.'); 
} 
?> 

在twitteroauth.php,我早些時候曾:

function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } 
    function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; } 
    function authorizeURL() { return 'https://twitter.com/oauth/authorize'; } 
    function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } 

但隨後嘗試:

function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } 
    function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; } 
    function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; } 
    function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } 

- 但沒有運氣。

+0

你會''session_start()'或是會話每次都會自動啓動嗎? – Arvin 2011-06-10 10:50:58

+0

我正在做一個session_start();但該行位於包含文件的其他位置......(位於引用代碼的上方) – siliconpi 2011-06-10 11:22:28

+0

您期望發生什麼? – abraham 2011-06-10 15:06:47

回答

4

答案:在twitter.com上設置的應用程序權限級別與我們所做的不匹配。從Twitter

消息:

如果您使用OAuth /驗證 方法,無需設置任何的 force_login或SCREEN_NAME參數, Twitter將只要用戶登錄 回重定向到您的 網站進入Twitter,並且您的 應用程序已具有有效的 OAuth訪問令牌。如果您最近有 切換您的應用程序的權限 級別(例如,從讀取/寫入到 讀取/寫入/ DM),此重定向將不會發生 ,因爲正在請求新的權限 。如果這沒有幫助,您可能還想在 我們的開發人員談話小組發佈關於此: http://groups.google.com/group/twitter-development-talk 。我們的API工程團隊以 爲基礎與 開發人員進行交流。

相關問題