I am following the article/example – artisansweb . net/tweet-twitter-php – to send Tweets via the Twitter API. The code below, or slight variations of it, is what I’m using. This all works very well in localhost. However, when transferred to my hosting site, InfinityFree . net, I get a fatal error in the authentication. I’ve double and triple checked that the reference files, .env keys/tokens & vender/abraham/twitterouath/twitteroauth are there in the same configuration as in my LAMP server. I use the .env file for other APIs without a problem.

<?php
require_once "vendor/autoload.php";
include('loadenv.php');
 
use Abraham\TwitterOAuth\TwitterOAuth;
 
define('CONSUMER_KEY', $_ENV['OAUTH_CONSUMER_KEY']);
define('CONSUMER_SECRET', $_ENV['OAUTH_CONSUMER_KEY_SECRET']);
define('ACCESS_TOKEN', $_ENV['OAUTH_ACCESS_TOKEN']);
define('ACCESS_TOKEN_SECRET', $_ENV['OAUTH_ACCESS_TOKEN_SECRET']);
 
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);

$status = 'Check out The Gifted: A Positive Tale of Mutation. ';
$post_tweets = $connection->post("statuses/update", ["status" => $status]);

echo 'Tweet Program Ended';

The error from the live version is in the image below. Is there any idea how I might go about tracking this down?

Hey which version of the library are you using? It sounds like a mismatch of SSL versions available on your end vs which ones are accepted on Twitter’s API side.

I loaded the library with composer. I assumed this would be the current version. My practice app does work in localhost to send Tweets through my account but when I transferred the library to my hosting site, with all of the appropriate updates for tokens, there I get confirmation errors.

It sounds like an issue with your hosting using an old version of some ssl related dependencies. Is it a managed service or are you managing it yourself? If it’s managed I’d bring it up with them.

I have a free account with infinityfree . net which does not offer much support, but I will try their forum. They have been helpful in the past. Thanks for getting back to me. Your input may help me to ask more intelligent questions.

1 Like

Just to add some more context, the error is being thrown in the library here which confirms that it’s a curl / ssl issue. I’m suspecting that the OpenSSL version on the hosting provider’s end is older than OpenSSL 1.0.1 which potentially doesn’t support newer cipher suites which are required by Twitter for security.

Thanks again!
I will use this input in the infinityfree forum which should get me a quicker solution to the problem. With composer, I’m not sure where they get their libraries from, but it is possible that infintyfree is not up to date. The security with Twitter seems very tight. When celebrities and politicians claim their accounts are hacked it makes me laugh.