使用 ionic cordova 中的 twitter 登录无法使用 $cordovaOauth.twitter [英] login with twitter in ionic cordova not working using $cordovaOauth.twitter
问题描述
我想使用 Cordova Oauth 插件在我的混合应用程序中集成 twitter 登录以验证用户,遵循 ngcordova oauth.
I want to integrate twitter login to validate user in my hybrid application using Cordova Oauth plugin, followed the instruction from ngcordova oauth.
此处的演示步骤,因为那里给出了关于回调 URI 必须指向的内容到 localhost/callback 否则,登录流程将不会完成,但是当我要在 Apps management 中设置它时,它会给出
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
错误客户端应用程序验证失败:URL 格式无效
我有控制台返回响应但没有收到任何警报,下面是我正在使用的代码
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));
});
}
推荐答案
已经创建了一个有效的 twitterExample 并上传到 github.请拿一个看
Have created a working twitterExample and uploaded in github. Please take a look
已添加以下步骤以供快速参考.
Have added the steps below for quick reference.
先决条件
创建一个 Twitter 应用程序并获取消费者密钥(API Key)和消费者秘密(API Secret).
步骤
1) 创建项目
2) cd 进入项目
3) 添加所需平台
4)下载ng-cordova.min.js"并添加到js文件夹
5)在cordova.js"路径上方的index.html"文件中添加ng-cordova.min.js"路径
6)在app.js"角度模块中添加依赖ngCordova"
7) 添加插件"cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git"来自终端
8) 下载sha1.js"文件并添加到js文件夹
9) 在索引文件中添加sha1.js"路径
10) 从终端输入bower install ng-cordova-oauth -S"
11) 将ng-cordova-oauth"文件路径添加到索引文件
12) 在app.js"角度模块中包含ngCordovaOauth"依赖
13) 将$cordovaOauth"添加到使用推特登录功能的控制器
14) 在 index.html
中添加控制器和 ng-click15) 在控制器中添加 twitter 登录功能,如 app.js 中所示(请将 api_key 和 api_secret 替换为您的 twitter 应用程序详细信息)
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)
感谢 Nic Raboy 提供的插件和博客.
Thanks to Nic Raboy for the plugin and blog.
这篇关于使用 ionic cordova 中的 twitter 登录无法使用 $cordovaOauth.twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!