0

I am trying to make an app with material design and angularjs to get the tweets using hashtag search.

getTweets: function(hashtag, since,$http) {
                    var cfg = {};
                    var paramSince = since ? '&since_id='+ since : '';
                    var queryUrl = 'https://api.twitter.com/1.1/search/tweets.json?q=%23'+hashtag+paramSince;
                   // var queryUrl = '/search?hashtag='+hashtag+paramSince;
                    var promise = $http.get(queryUrl, cfg).then(function (response) {                        
                        return response;
                    });
                    return promise;
        }

This API returns error 215, Bad Authentication Data

Here is the full application

STEPS TO REPRODUCE:

(i) Click Add Account

(ii)Login

(iii) Click finish

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • possible duplicate of [Twitter API returns error 215, Bad Authentication Data](http://stackoverflow.com/questions/12684765/twitter-api-returns-error-215-bad-authentication-data) – Ramesh Rajendran Sep 28 '15 at 12:01

1 Answers1

0

$http is undefined. You injected $http service into your twitterApp.services factory, then you (try) redeclared it inside the returned function getTweets. In this case there is no "magic", you call getTweets with two arguments, so $http becomes undefined. The solution is removing this parameter from getTweets and use $http as a closure.

UPDATE: There's no error handling in the process, you have to reject the promise when error occurs. This way you can also see the error comes from the server.

http://plnkr.co/edit/Lbb6EvwsjuecmFn5Vchd?p=preview

As you can see on the console, when trying to get connected, the server returns an origin error:

Error: Origin "http://run.plnkr.co/Of0F9UHpjhrqkjdw/" does not match any registered domain/url on oauth.io(…)

It's probably about settings in your server (in this case, oauth.io) in terms of CORS.

Roy Miloh
  • 3,381
  • 1
  • 18
  • 17