繁体   English   中英

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

[英]Twitter Digits - retrieve user account data with AngularJS

我正在使用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);
       });
}

执行获取请求时,错误为:

“ 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执行此获取请求?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM