So I am using Abraham’s TwitterOAuth library to login on twitter and post a picture with some text, it goes as normal, everything seems to work just fine but the twit is not being posted so I decided to use var_dump() to see the result of that twit and I get the following:
object(stdClass)#23 (1) { [“errors”]=> array(1) { [0]=> object(stdClass)#22 (2) { [“code”]=> int(89) [“message”]=> string(25) “Invalid or expired token.” } } }
I have been trying to look what that error is supposed to be or get a way to fix it but none of the solutions I found worked for me. The following is the part of my code where I make the tweet in my callback.php :
<?php
namespace Abraham\TwitterOAuth\Test;
require_once 'vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
$config = require_once 'config.php';
session_start();
$oauth_verifier = filter_input(INPUT_GET, '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' => 'It is I, the Test kitten' ,
'media_ids' => $result->media_id_string];
$result = $twitter->post('statuses/update', $parameters);
var_dump($result);
?>
The Anyone’s got an idea on how I can make this work or why I am getting that issue?
Thanks!