1

I am trying to display my Twitter feeds using Twitter API 1.1. I have been searching for this but didn't get a proper solution.I have tried this using Abraham/TwitterOAuth library and it works fine. But my new task is not to use any 3rd party libraries.

Here I tried using cURL,

<?php
  $options = array(
  CURLOPT_HTTPHEADER     => array('Authorization: OAuth oauth_consumer_key="aaaaaaa", oauth_nonce="bbbbbbb", oauth_signature="cccccc%ddddddd%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1426752199", oauth_token="eeeeeeeee-fffffffffffff", oauth_version="1.0"'),
  CURLOPT_HEADER         => false,
  CURLOPT_URL            => 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=2&screen_name=myscreen_name',
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_SSL_VERIFYPEER => false
);

  $feed = curl_init();
  curl_setopt_array($feed, $options);
  $json = curl_exec($feed);
  curl_close($feed);
  $twitter_data = json_decode($json);
  var_dump($twitter_data);
?>

and it returns with an error

 object(stdClass)#1 (1) {
 ["errors"]=>
    array(1) {
      [0]=>
      object(stdClass)#2 (2) {
        ["code"]=>
        int(215)
        string(24) "Could not authenticate you"
      }
    }
 }

I am not getting where I am going wrong. How to make it work?

Terence Eden
  • 14,034
  • 3
  • 48
  • 89
Ahalya Hegde
  • 1,571
  • 2
  • 18
  • 41
  • Why don't you want to use 3rd party libraries? – Terence Eden Mar 23 '15 at 09:54
  • Because I am not supposed to use 3rd party library, that is the assignment. – Ahalya Hegde Mar 24 '15 at 05:00
  • A school assignment? Try posting a bit more detail about what you've tried, why you think it should work, and what isn't working. – Terence Eden Mar 24 '15 at 10:00
  • It worked when I tried this code http://blog.jacobemerick.com/web-development/working-with-twitters-api-via-php-oauth/ But again I am getting the same error for Twitter search. – Ahalya Hegde Mar 24 '15 at 10:20
  • It is working for /statuses/user_timeline. But getting error: 32 when I give the url as /search/tweets.json?q=%23hashtag. I am not getting how to make it work. Thank you – Ahalya Hegde Mar 24 '15 at 11:34

1 Answers1

1

Ok. Here I found a solution. I found the below link very helpful. Posting it here so that it might help some other.

Twitter API returns error 215, Bad Authentication Data

Ahalya Hegde
  • 1,571
  • 2
  • 18
  • 41