2017-11-14 7 views
0

私はmeetup APIからの応答を取得することにちょっと悩んでいます。エラー私は取得しています:私はここにCORS Cross-Origin Resource Sharing (CORS)が、失敗している仕事にこれを得ることにすべての私の試みに少し読んだVueJSのプリフライトリクエストで斧を使用

var config = {'Access-Control-Allow-Headers': 'Authorization'} 

axios.get(`https://api.meetup.com/self/calendar?&sign=true&photo-host=public&page=20`, {headers: config}) 
.then(response => { 
    console.log(response.data) 
    this.posts = response.data 
}) 
.catch(e => { 
    this.errors.push(e) 
}) 

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

は、ここに私のコードです。

あなたの誰かがこれを少し光らせてくれますか?

おかげで、

マヌー

+1

:https://www.meetup.com/meetup_api/:1として – FailedUnitTest

答えて

1

あなたのAPIは同じホスト上で提供されていません。 nginxのようなリバースプロキシを使用するか、cors toggle extensionを使用してください。

0

私はこれを今すぐ使用しています。 @FailedUnitTestと@Manav Mandalの両方の提案を検討する価値があります。ただし、OAuthの代わりにAPIキーを使用すると簡単に見つかりました。また、私のプロキシは私のexpressJSサーバです。 同じオーバー

data() { 
    return { 
    cards: [], 
    errors: [] 
    }; 
}, 
created() { 
    axios.get('/anything') 
    .then(response => { 
    this.cards = response.data; 
    }) 
    .catch(e => { 
    this.errors.push(e); 
    }); 
} 

は、両方のサーバーを確認して、あなたのクライアントの実行:

var express = require('express'); 
var axios = require('axios'); 

// meetup API 
var instance = axios.create({ 
    baseURL: 'https://api.meetup.com/' 
}); 

app.get('/anything', function(req, res) { 
    const apiKey = 'yourKey'; 
    const isSigned = 'true'; 
    const photoHost = 'public'; 
    const pageCount = '20'; 
    const url = '/self/calendar?' + 'key=' + apiKey + '&sign=' + isSigned 
+ '&photo-host=' + photoHost + '&page=' + pageCount + ''; 

    instance.get(url) 
    .then(response => { 
    return res.send(response.data); 
    }) 
    .catch(e => { 
    return e; 
    }) 
}); 

とクライアント側:あなたは、次の線に沿って何かを持っているでしょう、サーバー側で

ポート。

よろしく、

マヌー私はあなたが最初のセットアップのOAuthに持って、このAPIのためにと考えてい

関連する問題