PHP - Twitter reverse auth credentials

0

I am working with the Twitter API in php, with the libraría of Abraham's Twitteroauth, everything is fine until the login, but when I redirect my callback file it gives me the error:

  

TwitterOAuthException: Reverse auth credentials are invalid.

I'm seeing that for some reason the session variables are lost in the redirect and it occurs to me to print the session variables to see what they give me but it does not matter that I use it does not show me anything!

Use var_dump () and I do not get anything, use an echo before to see if at least that would come out and I will not leave either.

On the login page I echo them and var_dump () if they work for me but in the callback one they do not. Here I leave my callback.php

callback.php

<?php

namespace Abraham\TwitterOAuth\Test;

session_start();

require_once 'vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;

$config = require_once 'config.php';

$oauth_verifier = filter_input(INPUT_GET, 'oauth_verifier');

echo "El oauth verifier: <br />";
var_dump($oauth_verifier);

if (empty($oauth_verifier) ||
    empty($_SESSION['oauth_token']) ||
    empty($_SESSION['oauth_token_secret'])
) {
    // something's missing, go and login again
    header('Location: ' . $config['url_login']);
}

// connect with application token
$connection = new TwitterOAuth(
    $config['consumer_key'],
    $config['consumer_secret'],
    $_SESSION['oauth_token'],
    $_SESSION['oauth_token_secret']
);

// request user token
$token = $connection->oauth("oauth/access_token", 
                           ["oauth_verifier" => $_REQUEST['oauth_verifier']]);

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

        $file_path = __DIR__ . '/260.jpg';

        $result = $twitter->upload('media/upload', ['media' => $file_path]);

        $parameters = ['status' => 'Tuit' , 'media_ids' => $result->media_id_string];

        $result = $twitter->post('statuses/update', $parameters);

?>

It is assumed that the variables of session $ _SESSION ['oauth_token'] and $ _SESSION ['oauth_token_secret'] do not exist because they are lost when redirected, so I do not know why they pass the first if, the error I get when I create the connection object as the variables of the session that were created in the previous login did not exist.

Any help with this? At least understand why I can not print anything in the callback.

Thank you!

    
asked by hOlim 26.09.2018 в 16:57
source

0 answers