GithubHelp home page GithubHelp logo

joshvar88 / ng-twitter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saimon24/ng-twitter

0.0 2.0 0.0 3.16 MB

AngularJS library for the Twitter REST Api

Home Page: http://devdactic.com/

JavaScript 100.00%

ng-twitter's Introduction

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

ng-twitter's People

Contributors

saimon24 avatar jehna avatar

Watchers

Joshva avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.