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/

相关文章:

facebook - Facebook 和 Twitter 上的用户名字和姓氏限制

javascript - 将动态元素/行添加到 Angularjs 中的多维 Json 数组

javascript - 使用其 ID 定位其他 iframe

javascript - 在父窗口和子窗口中使用 Array 类(javascript 问题)

javascript - 只播放一次 CSS 动画

java - 如何使用java从twitter上抓取推文

javascript - 滚动文本方法,适用于数组,不适用于字符串

javascript - 在替换 ng-repeat 之前调用自定义指令链接函数

javascript - 双数组形式

iphone - ShareKit twitter 和 UIWebView 的问题(无键盘)