2016-10-16 12 views
0

Instagram에서 일부 이미지를로드해야하는 사이트가 있습니다. Fetch를 사용하여 Instagram의 API에 요청합니다. 요청은 성공적이지만 요청을 처리 할 때이 오류가 발생합니다 (error SyntaxError: Unexpected end of input).Instagram API SyntaxError : 예기치 않은 입력의 끝

요청이 유효한 JSON으로 200으로 반환됩니다. Fetch 응답이 완료되면 응답이 비어있는 것처럼 보이므로 SyntaxError가 발생합니다.

http://jsbin.com/kohito/edit?html,js,console

나는 예에서 내 액세스 토큰을 제거했습니다.

답변

0

Client-Side (Implicit) Authentication 메서드를 사용하여 Instagram API를 사용하려면 jsonp과 함께 가야합니다. fetch-jsonp을 가져 와서 "가져 오기"요청을 할 수 있습니다.

<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch-jsonp/1.1.0/fetch-jsonp.min.js"></script> 
    <script> 
    fetchJsonp('https://api.instagram.com/v1/users/self/media/recent/?' + window.location.hash.split('#')[1], { 
    method: 'GET', 
    }).then(response => { 
    response.json().then((json) => { 
     console.log(json); 
    }); 
    }); 
    </script> 
관련 문제