A step by step and working example of twitter login using ionic and ng-cordova-oauth
Pre-requisites
Create a twitter app and get Consumer Key (API Key) and Consumer Secret (API Secret).
Steps
- Create a project
- cd into the project
- Add the required platform(s)
- Download "ng-cordova.min.js" and add to js folder
- Add the "ng-cordova.min.js" path in "index.html" file just above "cordova.js" path
- Add the dependancy "ngCordova" in "app.js" angular module
- Add the plugin "cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git" from terminal
- Download the "sha1.js" file and add to js folder
- Add the "sha1.js" path in index file
- Type bower "install ng-cordova-oauth -S" from terminal
- Add the "ng-cordova-oauth" file path to index file
- Include "ngCordovaOauth" dependancy in "app.js" angular module
- Add the "$cordovaOauth" to the controller which is using twitter login function
- Add the controller and ng-click in index.html
- Add the twitter login function in the controller as show in the app.js (Please replace the api_key and api_secret with your twitter app details)
Reference:
http://blog.ionic.io/oauth-ionic-ngcordova/
https://github.com/nraboy/ng-cordova-oauth
Thanks to Nic Raboy for the plugin and blog.