2017-03-04 65 views
0

我想讓我的初始GET調用檢索我的令牌請求的代碼。我搜索了幾個小時,我無法弄清楚爲什麼我得到一個CORS錯誤。我在管理面板中設置了重定向網址,幷包含在我的查詢參數中。我也試過沒有它。沒有任何工作。slack api請求代碼

它應該是這樣簡單嗎?

fetch(`https://slack.com/oauth/authorize?scope=identity.basic&client_id=xxxxxxxxx.xxxxxxx`) 
    .then(res => console.log(res)) 

ERROR

Fetch API cannot load https://slack.com/oauth/authorize?scope=identity.basic&client_id=148914445073.148918419105. Redirect from 'https://slack.com/oauth/authorize?scope=identity.basic&client_id=xxxxxxxx.xxxxxxxx' to 'https://slack.com/oauth/authorize?client_id=xxxxxx.xxxxx&scope=identity.basic&team=T4CSWD325' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. 

回答

0

您需要重定向用戶這個頁面,而不是異步通過獲取加載頁面的內容:d

這是頁面,用戶批准您的應用程序,之後它們將被重定向到您指定的回調。

大多數應用程序使用Add to Slack按鈕將其添加到他們的網站。

有關整個OAuth流程的更多信息,請訪問:https://api.slack.com/docs/oauth

相關問題