Keep getting "Bad Authentication Data" error code 215 with Abraham's Twitteroauth


#1

Hi, I’m new at twitter’s API and I don’t get how to make it work.
My goal is to connect to Twitter’s servers and retrieve a record of random tweets over a certain period of time (like 10 minutes) from the public stream.

Now, I signed up, I got the credentials and I wrote the code below using Abraham’s Twitteroauth:

<?php 

   require ('twitteroauth/twitteroauth.php');


   $consumerkey = '////////////';
   $consumersecret = '/////////////';
   $accesstoken = ' ////////////////';
   $accesstokensecret = '/////////////////';



    $connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
    
    

    $connection->host = "https://api.twitter.com/1.1/";
    $connection->ssl_verifypeer = TRUE;
    $connection->content_type = 'application/x-www-form-urlencoded';

   //sample should return a random set of tweets
	$content = $connection->get('https://stream.twitter.com/1.1/statuses/sample.json ');
    
    print_r ($content);
?> 


When I run this script, I get this error message:
[message] => Bad Authentication data
[code] => 215

I know this question has been asked lots of times before but I don’t seem to get any outcome anyway. Any tip?
Thanks


#2

TwitterOAuth doesn’t support the streaming API, I recommend looking at https://github.com/fennb/phirehose