Session twitter oAuth的会话将过期

Session twitter oAuth的会话将过期,session,twitter,oauth,Session,Twitter,Oauth,我正在使用Abraham Williams的oAuth库更新状态。应用程序没有UI(除了Twitter提示输入凭据之外)。相反,用户在浏览器中输入URL 当调用URL时,我得到一个错误:“无法发布Tweet。错误:原因:1” 我插入了一些测试代码,似乎会话在两次转换之间丢失了:$\u session['tweetmsg']在index.php的初始调用中设置,但是当切换到connect.php时,会话似乎丢失了。有什么想法吗 以下是源代码: index.php <?php include_

我正在使用Abraham Williams的oAuth库更新状态。应用程序没有UI(除了Twitter提示输入凭据之外)。相反,用户在浏览器中输入URL

当调用URL时,我得到一个错误:“无法发布Tweet。错误:原因:1”

我插入了一些测试代码,似乎会话在两次转换之间丢失了:$\u session['tweetmsg']在index.php的初始调用中设置,但是当切换到connect.php时,会话似乎丢失了。有什么想法吗

以下是源代码:

index.php

<?php
include_once '../../winsinclude/tw_config.php';
require_once "../../winsinclude/twitteroauth.php";
require_once "../../winsinclude/OAuth.php";
session_start();
if (empty($_SESSION['access_token'])) {
  $_SESSION['tweetmsg'] = create_tweet_text();
  print "<script>self.location='./connect.php');</script>";
}

$connection = new TwitterOAuth(
  CONSUMER_KEY,
  CONSUMER_SECRET,
  $_SESSION['access_token']['oauth_token'],
  $_SESSION['access_token']['oauth_token_secret']
);

if (!isset($_SESSION['tweetmsg'])) {
  exit('No tweet value in session or from form');
}
$tweetmsg = $_SESSION['tweetmsg'];
$result = $connection->post('statuses/update', array('status' => $tweetmsg));
unset($_SESSION['tweetmsg']);
if (200 === $connection->http_code) {
  echo 'Tweet Posted: '.$tweetmsg;
}
else {
  echo 'Could not post Tweet. Error: '.$httpCode.' Reason: '.
  session_destroy();
}
function create_tweet_text () {
  return 'this is a test';
}

最近Twitter停用了oAuth的许多http URL,并将其替换为https等价物。如果您可以在includes中看到URL字符串,则意味着您需要跟踪并更改对https的所有调用…

如果您阅读了我发布的源代码,您将看到我在没有特定端点的情况下不会调用Twitter API,并且我使用的是Abraham Williams的库,它在没有使用特定端点的情况下不会调用API库。
?php
session_start();
include_once '../../winsinclude/tw_config.php';
require_once "../../winsinclude/twitteroauth.php";
require_once "../../winsinclude/OAuth.php";

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK.'callback.php');

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

$url = $connection->getAuthorizeURL($request_token);
print "<script>self.location='$url';</script>";
<?php
session_start();
include_once '../../winsinclude/tw_config.php';
require_once "../../winsinclude/twitteroauth.php";
require_once "../../winsinclude/OAuth.php";

if (
  isset($_REQUEST['oauth_token']) 
  && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']
) {
  echo 'Session expired';
}
else {
  $connection = new TwitterOAuth(
    CONSUMER_KEY,
    CONSUMER_SECRET,
    $_SESSION['oauth_token'],
    $_SESSION['oauth_token_secret']
  );
  $_SESSION['access_token'] = $connection->getAccessToken($_REQUEST['oauth_verifier']);
  print "<script>self.location='index.php';</script>";
}