Ionic Framework Twitter integration



我目前正在做一个项目,在这个项目中,我必须使用Ionic Framework进行Twitter集成。

我正在使用离子论坛的示例程序:http://forum.ionicframework.com/t/twitter-integration-with-jsoauth/3936

可在Bitbucket获得:https://bitbucket.org/aaronksaunders/ionic.twitter.sample

我已经以两种方式对其进行了测试,即使用 ionic 服务和在模拟器上,但结果相同:每当我单击登录时,都会出现一个带有 adrress 的新浏览器窗口:https://api.twitter.com/oauth/authorize? 出现包含以下错误消息。

Whoa there!
There is no request token for this page. That's the special key we need
from applications asking to use your Twitter account. Please go back to
the site or application that sent you here and try again; it was probably 
just a mistake.

我已将我的推特API密钥和API密钥放在适当的位置。

我其实很喜欢用hello.js。

这是一个很棒的库,可以为您处理您的社交媒体令牌。

初始化示例:

hello.init({
    facebook : '12345678912345'
}, {
    // Define the OAuth2 return URL
    redirect_uri : 'http://adodson.com/hello.js/redirect.html'
});

登录:

hello( "facebook" ).login().then( function(){
    alert("You are signed in to Facebook");
}, function( e ){
    alert("Signin error: " + e.error.message );
});

登录后,您可以拨打您选择的社交媒体帐户的任何电话。

你应该尽可能使用 ngCordova。

Oauth 插件文档解释说,你需要使用 jsSHA 向 Twitter 进行身份验证。

要在项目中使用 Twitter,您必须在项目中包含开源库 jsSHA。这是因为Twitter需要使用HMAC-SHA1进行请求签名,而不是JavaScript中的原生版本。

更多信息可在 ngCordova Oauth 插件文档中找到。

尝试将 Cordova oAuth 插件与应用内浏览器插件结合使用,如 @darryn.ten 所示。以下是如何使用oAuth插件触发Twitter登录的示例:

控制器

 angular.module('myApp')
       .controller('MyAppCtrl', ['$scope', '$cordovaOauth', function($scope, $cordovaOauth) {
       $scope.twitterLogin = function() {
            $cordovaOauth.twitter(<consumer key>, <secret key>).then(function(r) {
                //retrieve oAuth token from result
            }, function(error) {
                //show error
            });
        }
    }])

视图

<a class="button button-calm" href="#" ng-click="twitterLogin()">Twitter Login</a>

请参阅此处的文档。

最新更新