이 코드를 작동 시키려면 내가 상상할 수있는 모든 것을했습니다. 나는 React를 사용하고있다. 나는 아래에 게시 한 종점이 있습니다. 나는 페치 (fetch)를 사용하고 나서 슈퍼 에이전트 (superagent)를 사용해 보았습니다. 이 두 가지 오류가 발생합니다. 참고로, 의도적으로 사용자 ID와 액세스 토큰을 "x'd"출력했습니다.Instagram API가 자바 스크립트를 액세스 제어 허용 원점
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