I am trying to get user details after user login from twitter by this link - https://api.twitter.com/1.1/account/verify_credentials.json
To do this first I request for oauth_token, in second step I called for signature and in last I tried to get user data using oauth_token and signature. In this last call I am getting "401 unauthorized error".
I have used this cordova plugin - http://ngcordova.com/docs/plugins/oauth/
I want to generate APK for android and ios.I am using cordova CLI to generate apk.
Here is my code -
class TwitterLoginCtrl extends BaseCtrl
@register 'TwitterLoginCtrl'
@inject '$scope', '$ionicPopup', 'WtaLoading', '$ionicLoading','$cordovaOauth','$http','$cordovaOauthUtility'
initialize: ->
@$scope.twitterSignIn = @twitterSignIn
twitterSignIn: =>
alert 'Twitter Nisarg'
@$cordovaOauth.twitter('[consumer key]','consumer secret').then ((result) =>
console.log JSON.stringify(result)
oauthObject =
oauth_consumer_key: '[consumer key]'
oauth_nonce: @$cordovaOauthUtility.createNonce(10)
oauth_signature_method: 'HMAC-SHA1'
oauth_timestamp: Math.round((new Date).getTime() / 1000.0)
oauth_version: '1.0'
oauth_token: result.oauth_token
signatureObj = @$cordovaOauthUtility.createSignature('GET', 'https://api.twitter.com/1.1/account/verify_credentials.json', oauthObject, oauthObject)
@$http(url: 'https://api.twitter.com/1.1/account/verify_credentials.json', method: 'GET' , params: angular.extend(oauthObject, oauth_signature: signatureObj.signature), format: "json"). then (data) => **// THIS CALL THROWS 401 UNAUTHORIZED ERROR**
console.log JSON.stringify(data)
), (error) ->
console.log error
EDIT
@$cordovaOauth.twitter('[consumer key]','consumer secret').then ((result) =>
Above call give me this result =>
{
"oauth_token":[access-token],
"oauth_token_secret":[access_token_secret],
"user_id":"4629415817",
"screen_name":"napster",
"x_auth_expires":"0"
}
Here every time I am getting x_auth_expires. Is it ok?
