0

我最近开始使用 twitteroauth 登录,这似乎在示例中工作(在此处找到)但当我合并 redirect.php 和 callback.php 时却没有。基于下面的脚本(集成在一些登录脚本中)一直在努力)第二部分工作正常(基于redirect.php),返回一个oauth_token和oauth_verifier,但第一部分(基于callback.php)似乎甚至没有启动。当 Twitter 将用户重定向到主页时应该这样做。

有什么想法/建议吗?

session_start();
require_once('socialCodes.php');    //where I keep my app ID and Secret
require_once('twitteroauth/twitteroauth.php');

if (isset($_GET['oauth_token'])) {
 $connection = new TwitterOAuth($twAppID, $twAppSec, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $connection->host = "https://api.twitter.com/1.1/";

  $access_token = $connection->getAccessToken($_GET['oauth_verifier']);

    $_SESSION['access_token'] = $access_token;

  unset($_SESSION['oauth_token']);
 unset($_SESSION['oauth_token_secret']);

 if (200 == $connection->http_code) {
        $userAccessToken = $access_token['oauth_token'];
     $userSecretToken = $access_token['oauth_token_secret'];
      $userID = $access_token['user_id'];
      $userName = $access_token['screen_name'];
    }

} else {
    $connection = new TwitterOAuth($twAppID, $twAppSec);
   $connection->host = "https://api.twitter.com/1.1/";

 $request_token = $connection->getRequestToken('myhomepage');

 $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

  switch ($connection->http_code) {
     case 200:
        $url = $connection->getAuthorizeURL($token);
        header('Location: ' . $url); 
        break;
   default:
   echo 'Could not connect to Twitter. Refresh the page or try again later.';
 }
}
4

1 回答 1

1

原来这是一个缓存问题,脚本现在可以工作了。

于 2013-06-21T16:22:23.807 回答