javascript - Twitter Digits - 使用 AngularJS 检索用户帐户数据

标签 javascript angularjs twitter twitter-digits

我正在使用 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' header 。因此不允许访问 Origin ' http://localhost:8000 '。响应的 HTTP 状态代码为 400”。

我已经尝试更改 $httpProvider 配置来修改 header ,但没有成功。

Digits 路由不接受 JSONP 请求。

如何使用 AngularJS 对 Twitter Digits API 执行此 get 请求?

最佳答案

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

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.
*/

关于javascript - Twitter Digits - 使用 AngularJS 检索用户帐户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32737331/

相关文章:

javascript - 显示 JSON

twitter - 向 Twitter 发布消息后的回调

python - 在 Twitter OAuth POST 请求上获取 401

javascript - 如何在使用文本溢出时获取删除的文本: ellipsis

javascript - Vue.js 中的样式元素

javascript - 如何在 JavaScript 中实现 MATLAB 的 "eig(A, B)"函数

angularjs - ng-grid 有条件地显示/隐藏列

javascript - 如何在新页面中显示选中的项目?

PHP 网站 - Twitter API + Abraham Oauth(无法找到 x_rate_limit_remaining )

javascript - 将事件结果传递给子组件