Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1101803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:05:18+00:00 2026-05-17T01:05:18+00:00

I am using abraham williams library to update twitter status using oauth. But I

  • 0

I am using abraham williams library to update twitter status using
oauth. But I am constantly getting:

session expired

error. How can I get around this?

This is my source:

connect.php:

<?php
session_start();
require_once 'twitteroauth/TwitterOAuth.php';
define("CONSUMER_KEY", "--------------------");
define("CONSUMER_SECRET", "---------------------------");

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken('http://127.0.0.1/callback.php');

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

$url = $connection->getAuthorizeURL($request_token);
header('Location: ' . $url);
?>

index.php:

<?php
session_start();

if (empty($_SESSION['access_token'])) {
header('Location: ./connect.php');
}

require_once 'twitteroauth/TwitterOAuth.php';
define("CONSUMER_KEY", "---------------");
define("CONSUMER_SECRET", "--------------------------------");

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

include("form.php");
$msg = $_POST['tweet'];

if (!empty($msg)) {
  $tweetmsg = $msg; }
else {
  exit('Post a tweet');
     }

$result = $connection->post('statuses/update', array('status' => $tweetmsg));
unset($_SESSION['tweetmsg']);
if (200 === $connection->http_code) {
   echo'tweet posted';
}
else {
$resultmsg = 'Could not post Tweet. Error: '.$httpCode.'  
Reason:'.$result->error;
echo $resultmsg;
}
?>

callback.php:

<?php
session_start();
require_once 'twitteroauth/TwitterOAuth.php';
define("CONSUMER_KEY", "---------------");
define("CONSUMER_SECRET", "------------------------------");

if (
  isset($_REQUEST['oauth_token'])
  && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']
) {
  //echo 'Session expired';
header('Location: ./connect.php');
}
else {
  $connection = new TwitterOAuth(
    CONSUMER_KEY,
    CONSUMER_SECRET,
    $_SESSION['oauth_token'],
    $_SESSION['oauth_token_secret']
  );
  $_SESSION['access_token'] =
$connection->getAccessToken($_REQUEST['oauth_verifier']);
header('Location: index.php');

unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
}
?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:05:19+00:00Added an answer on May 17, 2026 at 1:05 am

    callback.php is designed to be used once during each negotiation for an access token. Not each time you want to tweet.

    I recommend breaking your code into the following three files:

    connect.php

    <?php
    session_start();
    require_once 'twitteroauth/TwitterOAuth.php';
    define("CONSUMER_KEY", "--------------------");
    define("CONSUMER_SECRET", "---------------------------");
    
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
    $request_token = $connection->getRequestToken('http://127.0.0.1/callback.php');
    
    $_SESSION['oauth_token'] = $request_token['oauth_token'];
    $_SESSION['oauth_token_secret'] =
    $request_token['oauth_token_secret'];
    
    $url = $connection->getAuthorizeURL($request_token);
    header('Location: ' . $url);
    

    callback.php

    <?php
    session_start();
    require_once 'twitteroauth/TwitterOAuth.php';
    define("CONSUMER_KEY", "------------------");
    define("CONSUMER_SECRET", "----------------------------");
    
    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']);
      header('Location: index.php');
    }
    

    index.php

    <?php
    session_start();
    
    if (empty($_SESSION['access_token'])) {
      if (!empty($_POST['tweetmsg'])) {
        $_SESSION['tweetmsg'] = $_POST['tweet'];
      }
      header('Location: ./connect.php');
    }
    
    require_once 'twitteroauth/TwitterOAuth.php';
    define("CONSUMER_KEY", "------------------");
    define("CONSUMER_SECRET", "----------------------------");
    
    $connection = new TwitterOAuth(
      CONSUMER_KEY,
      CONSUMER_SECRET,
      $_SESSION['access_token']['oauth_token'],
      $_SESSION['access_token']['oauth_token_secret']
    );
    
    if (!empty($_POST['tweetmsg'])) {
      $tweetmsg = $_POST['tweetmsg'];
    } elseif (!empty($_SESSION['tweetmsg'])) {
      $tweetmsg = $_SESSION['tweetmsg'];
    } else {
      exit('No tweet value in session or from form');
    }
    
    $result = $connection->post('statuses/update', array('status' => $tweetmsg));
    unset($_SESSION['tweetmsg']);
    if (200 === $connection->http_code) {
      $resultmsg = 'Tweet Posted: '.$tweetmsg;
    }
    else {
      $resultmsg = 'Could not post Tweet. Error: '.$httpCode.' Reason: '.
      $result->error;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i m using Abraham twitteroauth class for updating the twitter status, but i stuck
I'm using abraham's twitter oauth class (https://github.com/abraham/twitteroauth) to connect and update twitter. I had
I'm using twitteroauth from https://github.com/abraham/twitteroauth like this: $Twitter = new TwitterOAuth(...); $Twitter->post('statuses/update', array('status' =>
I'm using https://github.com/abraham/twitteroauth library. I already created my app on Twitter, the callbacks are
I am new to twitter API and I am using the Abraham Williams PHP
I'm trying to install Abraham's twitteroauth library without using FOSTwitterBundle. I want to use
So Im using Abrahams Twitter library like this: Connect.php /* Build TwitterOAuth object with
I am having some problems with implementing the twitter api. I am using Abraham's
I'm using Abhraham's twitter API library. My index.php <?php ob_start(); session_start(); require_once 'twitteroauth/twitteroauth.php'; require_once
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.