Skip to content

saimon24/ng-twitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

ngTwitter

ngTwitter is an AngularJS Twitter REST API wrapper. The purpose of this library is to quickly and easily access all the Twitter API endpoints without having to worry about the request signing and signature.

Requirements

You need to have a Twitter app and a valid OAuth token.

Installing ngTwitter

Bower

Add this repository as dependency:

$ bower install ng-twitter-api --save

This will add the dependency to your project and to the bower.json file.

The JavaScript library must then be added to your index.html file found in your projects www directory:

<script src="../ng-twitter-api/dist/ng-twitter-api.min.js"></script>

Twitter requires HMAC-SHA1 signatures in their Oauth implementation. This project install jsSHA with bower so you only have to include the file:

<script src="../bower_components/jsSHA/src/sha1.js"></script>

Injecting:

Once added to your index.html file, you must inject the library into your app.js module. Make your app.js file look something like the following:

angular.module('starter', ['ngTwitter'])

Now ngTwitter is ready to use!

Using ngTwitter In Your Project

  1. Find your ClientId and your SecretId from your Twitter app.
  2. Grab you OAuth token inside your app. If you are using the Ionic Framework you should use the ngCordova library. After including it, your request for a OAuth token could look like this:
    $cordovaOauth.twitter(clientId, clientSecret).then(function (succ) {
        $twitterApi.configure(clientId, clientSecret, succ);
      }, function(error) {
        console.log(error);
    });

For a complete Ionic integration guide also check out my Blogpost How To Easily Use The Twitter REST Api With AngularJS.

If you got your OAuth token differently, just make sure to configure ngTwitter before making any other calls like this:

    $twitterApi.configure(clientId, clientSecret, oauthToken);

After configuring you can use all the endpoint wrapper. Each API call returns a promise. The success callback is the complete Twitter Rest response.

    $twitterApi.getHomeTimeline({count: 5}).then(function(data) {
      console.log(data);
    }, function(error) {
      console.log('err: ' + error);
    });

Available methods

The options object is optional on every request. Just check out the Twitter documentation what you want to send.

configure(string clientId, string clientSecret, object token);
getHomeTimeline(object options); // GET statuses/home_timeline
getMentionsTimeline(object options) // GET statuses/mentions_timeline
getUserTimeline(object options) // GET statuses/user_timeline
searchTweets(string keyword, object options); // GET search/tweets
postStatusUpdate(string statusText, object options); // POST statuses/update
getUserDetails(string user_id, object options); // GET users/show
getRequest(string full_twitter_api_url, object options); // GET custom url
postRequest(string full_twitter_api_url, object options); // POST custom url

Contribution Rules

All contributions must be made via the development branch. This keeps the project more maintainable in terms of versioning as well as code control.

Have a question or found a bug?

Message me on Twitter - @schlimmson

Follow my Blog Devdactic - https://devdactic.com

About

AngularJS library for the Twitter REST Api

Resources

Stars

Watchers

Forks

Packages

No packages published