【问题标题】:Twitter OAuth ProblemTwitter OAuth 问题
【发布时间】:2011-07-16 14:12:50
【问题描述】:

我正在尝试使用 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/

【问题讨论】:

  • 看起来会话变量没有从 index.php 中设置并传递。

标签: twitter twitter-oauth oauth-2.0


【解决方案1】:

您没有在第二页开始您的会话。只要你不调用 session_start(),你的 session 变量是不可用的

一些 PHP 设置已将其 php.ini 配置为自动启动您的会话,但是当我查看您的服务器设置时,我发现您没有在第二页上为您的 php 会话发送 cookie 标头,所以我很漂亮确保您的会话没有在您的第二页上开始...

【讨论】:

  • 是的,这就是问题所在。谢谢。只是确认 - 当我再次回到 index.php 授权后。它再次要求我允许。我怎样才能做到一次并下次自动登录?
  • 我应该为特定用户存储 OAuth 组件的凭据吗?
猜你喜欢
  • 2011-02-22
  • 2011-06-08
  • 1970-01-01
  • 2011-03-01
  • 2011-02-06
  • 1970-01-01
  • 2014-02-11
相关资源
最近更新 更多