2016-09-01 6 views
0

私はfetchを使用してデータを取得しています。そのよう :api/oEmbedを使用してVimeoのクリップからデータを取得しようとしているときにCORSの問題が発生する

getClipMetadata = (url) => { 
    const endpoint = 'http://www.vimeo.com/api/oembed.json'; 

    fetch(`${endpoint}?url=${encodeURIComponent(url)}`, { 
     method: 'get', 
     cache: 'no-cache', 
     mode: 'cors', 
     headers: new Headers({ 
     'Access-Control-Allow-Origin': '*', 
     'Content-Type': 'application/json' 
     }) 
    }) 
     .then((response) => { return response.json();}) 
     .then((res) => console.log("async response received", res)) 
     .catch((err) => console.log("ajax error -> ", err))  
    } 

だから私は取得エラーは、このです:
Response for preflight is invalid (redirect)

私はそれがVimeoの開発者のpageから非常に簡単に見えたと思いました。

私は間違っていますか?

+2

私はvimeo.com'むしろwww.vimeo.com' ''よりも、そのページの使用上の参照例のすべて。 Vimeoは 'www.'から 'www.'にリダイレクトする可能性が高い。 –

+0

あなたの答えは部分的に真実でした。ありがとうございました。 –

答えて

1

エンドポイントは'http://www.vimeo.com/api/oembed.json'ではなく'https://vimeo.com/api/oembed.json'で、送信していたヘッダーも問題を引き起こしていました。

ので、最終的な作業コードは次のようになります。

getClipMetadata = (url) => { 
    const endpoint = 'https://vimeo.com/api/oembed.json'; 

    fetch(`${endpoint}?url=${encodeURIComponent(url)}`, { 
     method: 'get', 
     cache: 'no-cache', 
     mode: 'cors', 

    }) 
     .then((response) => { return response.json();}) 
     .then((res) => console.log("async response received", res)) 
     .catch((err) => console.log("ajax error -> ", err))  
    } 
関連する問題