[英]Google Street View API CORS Issue when trying to access street view from localhost using Angular 2
[英]Handling CORS when developing from localhost using REST APIs - Streamlabs API
我確信這個問題會以某種方式被標記,但是數小時的搜索沒有提示任何可用的信息。
許多項目需要我使用各種 API。 當前項目使用 Twitch 和 Streamlabs API。 在嘗試訪問 /authorize 端點時,我遇到了 CORS 策略限制。 這是因為我的引用者/來源是本地主機。
我的問題在於其他人如何設置他們的環境以使其不成為問題。 我明白為什么 CORS 會阻止我(在某種程度上),但我不明白的是,如果localhost
有全面限制,我應該如何遠離生產服務器工作。
我也嘗試過在 fetch 中操作標頭以及使用[no-cors]
,但在這里也無濟於事。 有任何想法嗎?
// Starts authorization
getAuth() {
const data = fetch (`https://streamlabs.com/api/v1.0/authorize?client_id=${clientID}&response_type=code&redirect_uri=https%3A%2F%2Ftwitchinstudios.com&scope=donations.create%20donations.read%20alerts.write`, {
headers: {
"Origin" : "https://twitchinstudios.com",
"Referer" : "https://twitchinstudios.com"
},
mode: 'no-cors'});
const code = data.json.code;
console.log(code);
// Post to /token endpoint
const tokenCall = fetch (`https://streamlabs.com/api/v1.0/token?grant_type=authorization_token&client_id=knOhuT74QrSn8h1m8tU8ucrFfVIfUuVpll71ErbI&client_secret=${clientSecret}&redirect_uri=https%3A%2F%2Ftwitchinstudios.com&code=${code}`, {
method: 'POST',
mode: 'no-cors'
})
這里也是他們 API 的文檔: https : //dev.streamlabs.com/reference
這不是 CORS 問題,也不是 API 問題。 這是我理解的一個問題。
對於任何遇到此問題的人,請檢查是否傳遞了任何 Allow-Access 標頭,如果沒有傳遞,則您不打算從網頁級別訪問它。
相反,允許我的節點服務器處理請求允許我訪問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.