![](/img/trans.png)
[英]**No 'Access-Control-Allow-Origin' header is present on the requested resource.**
[英]No 'Access-Control-Allow-Origin' header is present on the requested resource. - React/Node API
我正在嘗試使用Twitter進行護照認證。 我的設置如下:React(帶有redux)前端(create-react-app),Node(帶有express)API。 兩者都在localhost(不同的端口)上運行。
用戶轉到/login
並單擊調度登錄操作的按鈕:
export function login() {
return dispatch => {
return axios.get('/api/auth/twitter')
.then(() => {})
}
}
服務器上的路由:
router.get('/twitter', passport.authenticate('twitter'));
以及回調的路線:
router.get('/twitter/callback', passport.authenticate('twitter', {failureRedirect: '/login'}), loginSuccess);
loginSuccess
目前不執行任何操作。
這是我得到的完整錯誤:
XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=fGVctgAAAAAA1y22AAABXah3t3o. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:3000' is therefore not allowed access.
我正在將請求從React前端(localhost:3000)代理到localhost:8080。
如果我進入chrome devtools的網絡標簽,然后從twitter api中選擇響應,則如下所示:
如果有人知道如何通過護照設置者身份驗證來使用這種設置,請告訴我。
不幸的消息是,Twitter不允許您調用其API客戶端,您需要一台服務器才能做到這一點:(
看看這個Quora的答案 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.