how can I access user details through "oauth_token" from twitter api in ionic framework

4.9k views Asked by At

I am new to Twitter API and trying to authenticate and get user details from end point using oauth_token, but don't know how to achieve it.

.controller('loginCtrl', function ($scope, $cordovaOauth, $state, $localStorage, $http) {
        $scope.twitterAuthentication = function () {
            var ht = window.innerHeight - 57 + 'px';
            $cordovaOauth.twitter("fzyTifF0ZwCCOug5C12CUyu1x", "zXT3o1amVWPfgUNiUsX4w1aU0mZqqFn8KtUaIkhU1rsF97ROPh").then(function (result) {
                $scope.data = result;
                $localStorage.oauth_token = result.oauth_token;
                $localStorage.twitter_user_id = result.user_id;
                $localStorage.oauth_token_secret = result.oauth_token_secret;
                $localStorage.stored_token = JSON.stringify(result);

                $state.go('app.twitter', {height: ht});

                //This will go to TwitterCtrl

            }, function (error) {
                alert(JSON.stringify(error));
            });
        }
})
.controller('TwitterCtrl', function ($scope, $http, $localStorage, $stateParams, $cordovaOauthUtility) {
     var oauth_token = $localStorage.oauth_token;
     var oauth_token_secret = $localStorage.oauth_token_secret;
})

I am able to signin to twitter api and getting oauth_token & oauth_token_secret, but how to get detail from it ? I am stucked here. Trying to fetch details from twitter REST APIs, but don't understand how to get. I find this answer but it also doesn't worked for me. Wasted 2 days.

1

There are 1 answers

0
MPMP On

Use https://dev.twitter.com/rest/reference/get/users/show, which has to pass auth1.0 header like login auth header, required parameters.

Don't forget to include $cordovaOauthUtility which is useful to create signature.