Twitter API Validates in Localhost But Not on Infinityfree

epiz_28063674 Website michaelsbookcorner.com

I have created a small app in php for sending a Tweet utilizing Twitter’s API. The script will send a Tweet as expected in localhost but when this file is transferred to Infinityfree there seems to be an error in the authentication. The same library is used along with the same API tokens and keys. The same text reference files used have also been uploaded. The error I get is shown below.

From the Twitter Development Community forum I received these comments.


It sounds like an issue with your hosting using an old version of some ssl related dependencies.

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.


Fatal error : Uncaught Abraham\TwitterOAuth\TwitterOAuthException: error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error in /home/vol11_4/epizy.com/epiz_28063674/michaelsbookcorner.com/htdocs/vendor/abraham/twitteroauth/src/TwitterOAuth.php:709 Stack trace: #0 /home/vol11_4/epizy.com/epiz_28063674/michaelsbookcorner.com/htdocs/vendor/abraham/twitteroauth/src/TwitterOAuth.php(598): Abraham\TwitterOAuth\TwitterOAuth->request(‘https://api.twi…’, ‘POST’, ‘Authorization: …’, Array, false) #1 /home/vol11_4/epizy.com/epiz_28063674/michaelsbookcorner.com/htdocs/vendor/abraham/twitteroauth/src/TwitterOAuth.php(531): Abraham\TwitterOAuth\TwitterOAuth->oAuthRequest(‘https://api.twi…’, ‘POST’, Array, false) #2 /home/vol11_4/epizy.com/epiz_28063674/michaelsbookcorner.com/htdocs/vendor/abraham/twitteroauth/src/TwitterOAuth.php(483): Abraham\TwitterOAuth\TwitterOAuth->makeRequests(‘https://api.twi…’, ‘POST’, Array, false) #3 /home/vol11_4/epizy.com/epiz_28063674/michaelsbookcorner.com/htdocs/vendor/abraham/twitte in /home/vol11_4/epizy.com/epiz_28063674/michaelsbookcorner.com/htdocs/vendor/abraham/twitteroauth/src/TwitterOAuth.php on line 709

For reference this is the code in question

<?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);

    //  SET A RANDOM URL WITH TWITTER CARD FROM FILE promoURLs.txt
    $var = file_get_contents('promoURLs.txt'); //Take the contents from the file to the variable
    $result = explode(',',$var); //Split it by ','
    $url = $result[array_rand($result)]; //Return a random entry from the array.

    //  BUILD A STRING OF HASHTAGS LESS THAN OR EQUAL TO 140 CHARS hashtags.txt
    $hashtags = '';
    while(strlen($hashtags) < 90) {
        $var = file_get_contents('hashtags.txt'); //Take the contents from the file to the variable
        $result = explode(',',$var); //Split it by ','  
        $hashtag = $result[array_rand($result)]; //Return a random entry from the array.    
        $hashtags = $hashtags.' '.$hashtag;

    }
    echo '</br> hashtags is </br>';
    echo $hashtags;

    $status = 'Classic Science Fiction '.$hashtags.' '.$url;
    $post_tweets = $connection->post("statuses/update", ["status" => $status]);
//   $postArray = json_decode($post_tweets, true);
    echo '</br></br>Tweet message is </br>'.$status;

    $post_tweets_array = (array)$post_tweets;
//    echo "</br></br>Post Tweets Array :".'</br>';
//    var_dump($post_tweets_array);

//    echo 'Post Tweets is </br></br>';
//    var_dump($post_tweets);
//    $pageURL = $_POST['pageURL'];
    


    

You might not get it to work here. Lots of network things are configured oddly (for security) and that could prevent some things, such as the Twitter API, from working

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.