2011-06-10 110 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工程团队以 为基础与 开发人员进行交流。

相关问题