[英]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.