Why does oauth with pin doesn`t work?

php

#1
<?php  
//this is file1
error_reporting(E_ALL ^ E_NOTICE);
require_once '../vendor/autoload.php';
use \Abraham\TwitterOAuth\TwitterOAuth as tOauth;
require_once '4.2.php';//which defines MY_CONSUMER_KEY,MY_CONSUMER_SECRET

session_start();
$twitterOAuth = new tOAuth(MY_CONSUMER_KEY,MY_CONSUMER_SECRET);

$requestTokens=$twitterOAuth->oauth('/oauth/request_token');

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

header("Location:".$twitterOAuth->url("oauth/authorize",array("oauth_token"=>$requestTokens['oauth_token'])));`
//gets the pin
?>
<?php
//this is file2
require_once '../vendor/autoload.php';
use \Abraham\TwitterOAuth\TwitterOAuth as tOauth;
require_once '4.2.php';
session_start();
$twitterOAuth = new tOAuth(MY_CONSUMER_KEY, MY_CONSUMER_SECRET,$_SESSION['request_token'], $_SESSION['request_token_secret']);

$accessOAuthTokens = $twitterOAuth->oauth("oauth/access_token", ["oauth_verifier" => $_GET['pin']]);
if ($accessOAuthTokens && $accessOAuthTokens['oauth_token']) {

    $_SESSION['access_token'] = $accessOAuthTokens['oauth_token'];
    $_SESSION['access_token_secret'] = $accessOAuthTokens['oauth_token_secret'];
    echo 'success';
} else {
    print "error:pin used time out";
    return false;
}
//file1 works fine i can get the pin everytime,but file2 always get Fatal error

/*
Fatal error: Uncaught exception ‘Abraham\TwitterOAuth\TwitterOAuthException’ with message ‘Error processing your OAuth request: Invalid oauth_verifier parameter’
*/


#2

It looks like you are calling TwitterOAuth correctly. I would recommend you print $_GET['pin'] out to make sure it’s the value you expect. Also if you are using $_GET are you accessing these pages in a browser?