An angular module that can be used to make calls to Twitter API for applications using user-based authentication.
The Module simplifies the two step process into a single step and helps make Twitter API Calls easier.
-
Include twitter-oauth-lib.js (from dist) in your html page(of ionic app).
-
Include a dependent sha file sha
-
Inject the module as dependency in your angular app.
angular.module("myapp", ["twitter-oauth"]);
/* Using in App with the factory */
angular.module("myapp").controller("SomeController", function($scope, $twitterOAuth) {
});
- $twitterOAuth.init(consumer_key, consumer_secret)
Use the consumerKey and consumerSecret from the app created in twitter.
- $twitterOAuth.connect()
Returns a promise. Here ngCordovaOAuth is utilized and twitter authentication process is done. After successful completion oauth_token and oauth_token_secret will be received which will be utilized to make API Calls.
- $twitterOAuth.call(url)
URL here is the actual twitter API call. It is recommended to use this once the promise is connect is resolved and within the sucess case.
angular.module("myapp").controller("SomeController", function($scope, $twitterOAuth) {
$twitterOAuth.init(consumer_key, consumer_secret);
$twitterOAuth.connect().then(function(data) {
/* Make API calls here */
var url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=<twitter_handle>&count=2"
$twitterOAuth.call(url).then(function(data) {
console.log(data);
}, function(err) {
});
}, function(err) {
});
});