简体   繁体   English

Twitter登录Cordova和Angularjs:401未经授权的错误

[英]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.

相关问题 在AngularJS中有401个未经授权的错误处理 - 401 unauthorized error handling in AngularJS 401未经授权的错误与$ http和angularjs中的hedear参数 - 401 Unauthorized error with $http and hedear param in in angularjs 如果刷新(JWT)令牌未经授权,AngularJS重定向到登录(401响应) - AngularJS redirect to login if Refresh (JWT) token gets unauthorized (401 response) 重定向时Angularjs Satellizer Twitter登录CORS错误 - Angularjs Satellizer Twitter login CORS error on redirect 401(未经授权)Get 方法错误 - 401 (Unauthorized) Error on Get method 在localhost:3000上的angularjs中获取未经授权的401作为后端 - Getting unauthorized 401 in angularjs on localhost:3000 for backend 使用 JWT 处理 401(未经授权)angularjs 身份验证 - Handling 401 (Unauthorized) angularjs Authentication using JWT AngularJS:401-未经授权:具有基本身份验证的HttpInterceptor - AngularJS: 401 - Unauthorized: HttpInterceptor with Basic Auth 在Grails应用程序中使用Spring Security Rest插件调用登录时出现401未经授权的错误 - 401 unauthorized error while call to login with spring security rest plugin in grails app 401 $ http或Restangular错误捕获未捕获对登录表单的未经授权的响应? - 401 Unauthorized response to login form not being caught by $http or Restangular error catching?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM