【发布时间】: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