私は、このコードを動作させるために私が想像できるすべてを行っています。私はReactを使用しています。私は以下に投稿したエンドポイントを持っています。フェッチしてからスーパーエージェントを使ってみました(多分重要です)、どちらもうまく動作しませんでした。私はこれらの2つのエラーを取得します。参考までに、私はuserIdとアクセストークンを意図的に「x'd」出しました。Instagram api get JavaScriptアクセス制御 - 許可 - 起点
OPTIONS https://api.instagram.com/v1/users/xxxxxxxxx/media/recent/?access_token=xxxxxxxx 405()
と
Failed to load https://api.instagram.com/v1/users/xxxxxxx/media/recent/?access_token=xxxxxx: 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:3000' is therefore not allowed access. The response had HTTP status code 405.
私はthis postとthis postを試してみましたが、彼らのソリューションを実装しますが返された一つの目的は、私は必要なデータを持っていなかった、もう一方がちょうどなかったです作業。しかし、ブラウザに完全なURLを貼り付けると、JSONオブジェクトを取得することができます。助けてください。
export const getIGPost =() => dispatch => {
// fetch('https://api.instagram.com/v1/users/xxxxxxxx/media/recent/?
access_token=xxxxxxx',{
// method:'GET',
// dataType:'jsonp',
// crossDomain:true
// })
request
.get(`https://api.instagram.com/v1/users/xxxxxxxxx/media/recent/?access_token=xxxxxxxxx`)
.set('Access-Control-Allow-Origin', 'http://localhost:3000')
.then(res => {
if(res.ok) {
console.log(res.body)
// dispatch(addIGPost(res.body))
}
})
}
[instagram apiでのAccess-Control-Allow-Originの複製](https://stackoverflow.com/questions/41486160/access-control-allow-origin-with-instagram-api) – jcaron
@jcaron tride thatあなたが私がコメントアウトしたフェッチで伝えることができるように – str8up7od