【发布时间】:2011-09-12 09:52:12
【问题描述】:
我认为我已经正确实现了 twitter oauth,但是每次用户在我的网站上单击通过 twitter 登录时,他都会被重定向到 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'; }
也 - 但没有运气。
【问题讨论】:
-
你是
session_start()还是每次都自动开始会话? -
我正在做一个 session_start();但该行位于包含文件中的其他位置...(在引用的代码上方)
-
您期望发生什么?
-
@abraham - 你是github.com/abraham/twitteroauth名气的亚伯拉罕吗? :) :) 我的应用程序连接到 twitter,但是每次都会提示用户授权应用程序 - 我不确定为什么会这样。我可以测试什么来进一步诊断?
-
@abraham - 需要帮助! :) 当然不能指望用户每次都授权应用程序!
标签: twitter oauth twitter-oauth