Twitter OAuth通过localhost连接,在实时版本上失败?

时间:2011-08-04 15:23:04

标签: php twitter

redirect.php没有正确抓取访问令牌似乎是一个问题。我浏览了一下,发现很多人都有这个问题,但我无法弄清楚如何解决它。此相同的代码适用于localhost,但在我的实时版本上失败。任何想法为什么/如何解决它?有没有办法可以手动设置这些?

<?php

/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');

/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);

/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
  case 200:
    /* Build authorize URL and redirect user to Twitter. */
    $url = $connection->getAuthorizeURL($token);
    header('Location: ' . $url); 
    break;
  default:
    /* Show notification if something went wrong. */
    echo 'Could not connect to Twitter. Refresh the page or try again later.';
}

1 个答案:

答案 0 :(得分:0)

http://dev.twitter.com/apps/中验证回调网址 它可能指向错误服务器上的redirect.php