1

I trying to get streaming data from twitter, I found curl in twitter developer section to get streaming data

$ curl --request GET 
 --url 'https://api.twitter.com/1.1/search/tweets.json?q=nasa&result_type=popular' 
 --header 'authorization: OAuth oauth_consumer_key="consumer-key-for-app", 
 oauth_nonce="generated-nonce", oauth_signature="generated-signature", 
 oauth_signature_method="HMAC-SHA1", oauth_timestamp="generated-timestamp", 
 oauth_token="access-token-for-authed-user", oauth_version="1.0"'

But i found how to use curl to get data at http://collaboradev.com/2011/04/01/twitter-oauth-php-tutorial/ But I am getting

{"errors":[{"code":215,"message":"Bad Authentication data."}]}

I checked my credential but could not solve ,problem persists: My code is below ::

 $nonce = time();
        $timestamp = time();
        $oauth = array('oauth_callback' => 'https://localhost/twitter/curl.php',
              'oauth_consumer_key' => 'bGLk7nhcMySEulFeRICCMdmtk',
              'oauth_nonce' => $nonce,
              'oauth_signature_method' => 'HMAC-SHA1',
              'oauth_timestamp' => $timestamp,
              'oauth_version' => '1.0');

        function buildAuthorizationHeader($oauth){
        $r = 'Authorization: OAuth '; //header prefix

        $values = array(); //temporary key=value array
        foreach($oauth as $key=>$value)
        $values[] = "$key=\"" . rawurlencode($value) . "\""; //encode key=value string

        $r .= implode(', ', $values); //reassemble
        return $r; //return full authorization header
        }

        $header = array( buildAuthorizationHeader($oauth), 'Expect:');


        $options = array(CURLOPT_HTTPHEADER => $header, //use our authorization and expect header
                           CURLOPT_HEADER => false, //don't retrieve the header back from Twitter
                           CURLOPT_URL => 'https://api.twitter.com/1.1/search/tweets.json?q=nasa&result_type=popular', //the URI we're sending the request to
                           CURLOPT_POST => true, //this is going to be a POST - required
                           CURLOPT_RETURNTRANSFER => true, //return content as a string, don't echo out directly
                           CURLOPT_SSL_VERIFYPEER => false);



    $ch = curl_init(); //get a channel
    curl_setopt_array($ch, $options); //set options
    $response = curl_exec($ch); //make the call
    curl_close($ch); //hang up
    echo $response;
Ashutosh Roy
  • 81
  • 2
  • 10
  • FWIW: [Twitter API returns error 215, Bad Authentication Data](https://stackoverflow.com/questions/12684765/twitter-api-returns-error-215-bad-authentication-data) Source you copied your code from had a few upvotes and nothing jumps out so dunno. Could always leverage: https://github.com/abraham/twitteroauth – ficuscr Oct 18 '18 at 20:32
  • Unfortunately twitteroauth doesn't support streaming however https://github.com/fennb/phirehose is built for it - although it hasn't now been updated in a while. – Antony Feb 05 '20 at 09:15

0 Answers0