login with twitter in ionic cordova not working us

2019-02-17 15:24发布

问题:

I want to integrate twitter login to validate user in my hybrid application using Cordova Oauth plugin, followed the instruction from ngcordova oauth.

And demonstration steps from Here, as there given that about callback URIs must point to localhost/callback otherwise, the login flow will not complete but in when I am going to set in Apps management its giving

Error The client application failed validation: Not a valid URL format

I have console the return response but not getting any alert, below code I am using

$scope.twitterLogin = function() {
$cordovaOauth.twitter("6VjHDXXXXXXXXXXXX", "erN45XbC3b35XXXXXXXXXXXX").then(function(result) {
            alert('ok111');
            alert(JSON.stringify(result));
        }, function(error) {
            alert(JSON.stringify(error));
        });
}

回答1:

Have created a working twitterExample and uploaded in github. Please take a look

Have added the steps below for quick reference.

Pre-requisites
Create a twitter app and get Consumer Key (API Key) and Consumer Secret (API Secret).

Steps
1) Create a project
2) cd into the project
3) Add the required platform(s)
4) Download "ng-cordova.min.js" and add to js folder
5) Add the "ng-cordova.min.js" path in "index.html" file just above "cordova.js" path
6) Add the dependancy "ngCordova" in "app.js" angular module
7) Add the plugin "cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git" from terminal
8) Download the "sha1.js" file and add to js folder
9) Add the "sha1.js" path in index file
10) Type "bower install ng-cordova-oauth -S" from terminal
11) Add the "ng-cordova-oauth" file path to index file
12) Include "ngCordovaOauth" dependancy in "app.js" angular module
13) Add the "$cordovaOauth" to the controller which is using twitter login function
14) Add the controller and ng-click in index.html
15) 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)

Thanks to Nic Raboy for the plugin and blog.



回答2:

i used http://127.0.0.1:8080/callback when creating the twitter application and it worked