AngularJS and Twitter API

Discussion in 'JavaScript' started by Earl Sargent, Apr 8, 2015.

  1. #1
    Hey everyone,

    I'm trying to create a custom Twitter feed for a website that I have, with AngularJS. So far, I think I have the authentication correct. I just can't seem to understand how to pull and display the tweets from the Twitter account that I created. I don't want to use http.get. I would like to stick with the $resource function and ng-resource. Here is what my authentication looks like.
    var OAuth = require('OAuth');
    var oauth = new OAuth.OAuth(
          'https://api.twitter.com/oauth/request_token',
          'https://api.twitter.com/oauth/access_token',
          'AUTH1',
          'AUTH2',
          '1.0A',
          null,
          'HMAC-SHA1'
        );
        oauth.get(
          'https://api.twitter.com/1.1/statuses/home_timeline.json',
          'KEY1',
          //you can get it at dev.twitter.com for your own apps
          'KEY2',
          //you can get it at dev.twitter.com for your own apps
          function (e, data, res){
            if (e) console.error(e);       
            console.log(require('util').inspect(data));
            done();     
          });   
    });
    Code (JavaScript):
    Is this the correct way to authenticate for Twitter? If so, how would I go about making the GET request to their API? The link that I have for the home timeline feed looks like this:

    https://api.twitter.com/1.1/statuses/home_timeline.json.

    I know that I'm supposed to access the JSON file, but I don't know how using $resource.

    Here is the Twitter dev link for reference:

    https://dev.twitter.com/rest/reference/get/statuses/home_timeline

    Thanks!
     
    Earl Sargent, Apr 8, 2015 IP