【问题标题】:Twitter OAuth keeps redirecting to https://twitter.com/oauth/authenticate?oauth_token=XYZTwitter OAuth 不断重定向到 https://twitter.com/oauth/authenticate?oauth_token=XYZ
【发布时间】: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


【解决方案1】:

答案:在 twitter.com 上设置的应用程序权限级别与我们所做的不匹配。

来自 Twitter 的消息:

如果您使用 oauth/authenticate 方法而不设置 force_login 或 screen_name 参数, Twitter 将重定向回您的 只要用户登录网站 进入 Twitter 并且已经有一个有效的 您的 OAuth 访问令牌 应用。如果你最近有 切换了您的应用程序的权限 级别(例如,从读/写到 读/写/DM),这个重定向不会 发生新的许可后 请求。如果这没有帮助,你 可能还想在 我们的开发者谈话组: http://groups.google.com/group/twitter-development-talk .我们的 API 工程团队互动 定期与这里的开发人员 基础。

【讨论】:

    猜你喜欢
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 1970-01-01
    • 2019-05-06
    • 2011-11-14
    • 2016-12-26
    相关资源
    最近更新 更多