简体   繁体   English

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

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

I'm using AngularJS to retrieve the user account data from 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);
       });
}

When performing get request the error is: 执行获取请求时,错误为:

"XMLHttpRequest cannot load https://api.digits.com/1.1/sdk/account.json . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:8000 ' is therefore not allowed access. The response had HTTP status code 400". “ XMLHttpRequest无法加载https://api.digits.com/1.1/sdk/account.json 。所请求的资源上没有'Access-Control-Allow-Origin'标头。来源' http:// localhost:8000 '因此,不允许访问。响应的HTTP状态代码为400“。

I have already tried to change the $httpProvider config to modify the headers but it didn't work. 我已经尝试过更改$ httpProvider配置来修改标头,但没有用。

The Digits route does not accept JSONP requests. Digits路由不接受JSONP请求。

How can I perform this get request to the Twitter Digits API using AngularJS? 如何使用AngularJS向Twitter Digits API执行此获取请求?

according to the documentation and the example, you must make an async call to your own server endpoint and that endpoint is supposed to do this and send back the user data. 根据文档和示例,您必须对自己的服务器端点进行异步调用,并且该端点应该这样做并发送回用户数据。

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

says

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