【问题标题】:Twitter Digits - retrieve user account data with AngularJSTwitter Digits - 使用 AngularJS 检索用户帐户数据
【发布时间】:2015-09-23 10:37:14
【问题描述】:

我正在使用 AngularJS 从 Twitter Digits 检索用户帐户数据。

Digits.logIn()
            .done(onLogin)
            .fail(onLoginFailure);



function onLogin(loginResponse) {
       console.log('Digits login succeeded.');
       var oAuthHeaders = parseOAuthHeaders(loginResponse.oauth_echo_headers);
       apiURL = oAuthHeaders.apiUrl;
       credentials = oAuthHeaders.credentials;

   $http.get(apiURL,{
           headers: {'Authorization': credentials}
       }).then(function(response) {
           // this callback will be called asynchronously
           // when the response is available
           console.log(response);
       }, function(response) {
           // called asynchronously if an error occurs
           // or server returns response with an error status.
           console.log(response);
       });
}

执行get请求时报错:

“XMLHttpRequest 无法加载 https://api.digits.com/1.1/sdk/account.json。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问源“http://localhost:8000”。响应的 HTTP 状态代码为 400”。

我已经尝试更改 $httpProvider 配置以修改标头,但没有成功。

Digits 路由不接受 JSONP 请求。

如何使用 AngularJS 向 Twitter Digits API 执行此获取请求?

【问题讨论】:

    标签: javascript angularjs twitter twitter-digits


    【解决方案1】:

    根据文档和示例,您必须对自己的服务器端点进行异步调用,并且该端点应该执行此操作并发回用户数据。

    https://github.com/twitterdev/cannonball-web/blob/master/public/javascripts/cannonball.js

    /**
    * Handle the login once the user has completed the sign in with Digits.
    * We must POST these headers to the server to safely invoke the Digits API
    * and get the logged-in user's data.
    */
    

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 2014-12-13
      • 2020-04-01
      • 1970-01-01
      • 2019-12-18
      • 2023-02-15
      • 1970-01-01
      • 2016-08-16
      • 2013-02-22
      相关资源
      最近更新 更多