[英]Twitter Login with Cordova and Angularjs: 401 unauthorized error
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
我试图通过此链接从用户登录后获取用户详细信息 -
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 . 为了做到这一点,我首先请求oauth_token ,第二步我要求签名 ,最后我尝试使用oauth_token和签名获取用户数据。 In this last call I am getting "401 unauthorized error" .
在最后一次通话中,我收到了“401未经授权的错误” 。
I have used this cordova plugin - http://ngcordova.com/docs/plugins/oauth/ 我使用过这个cordova插件 - http://ngcordova.com/docs/plugins/oauth/
I want to generate APK for android and ios.I am using cordova CLI to generate apk. 我想生成APK for android和ios.I我正在使用cordova CLI生成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 . 每次我得到x_auth_expires 。 Is it ok?
好吗?
As per documentation , 根据文件 ,
Error Codes & Responses HTTP Status Codes listed says 错误代码和响应列出的HTTP状态代码说
,
,
When I referred Twitter OAuth : Invalid or expired token [its NOT duplicate] , once you get the callback, initialize the class again with new access token. 当我提到Twitter OAuth:无效或过期的令牌[它不重复]时 ,一旦获得回调,再次使用新的访问令牌初始化该类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.