Instagram API 연동을 개발 하면서 공식문서에는 디테일한 설명없이 큰그림으로만 설명돼 있어서 개인적으로 많이 어려웠다. 그래서 많은 사람들에게 도움이 되고자 글을 작성한다. 언제든 질문과 지적은 환영이다!
Instagram 기본 디스플레이 API는 기본정보, 게시물(사진,동영상,글)의 정보만을 가져올 수 있다면, Instagram 그래프 API는 + 댓글관리, @를 통한 게시물 구분 등 더 디테일한 작업이 가능하다.
홈페이지에서 가입을 먼저 한다. (sns로 사용하던 facebook ID가 아님)
가입하고 내앱 > 앱 만들기를 누르면 해당 화면이 나오고 앱 유형을 선택 > '다음'버튼
(본인은 소비자를 선택했다.)
그리고 개발할 때 facebook for Developer 상단에 '앱 모드'가 있는데 개발로 선택해야 error 없이 데이터를 받을 수 있다.
여기까지 개발을 위한 기본준비 완료
https://api.instagram.com/oauth/authorize
?client_id={app-id}
&redirect_uri={redirect-uri}
&scope=user_profile,user_media
&response_type=code
인증 창 URL을 구성한 후 {app-id}는 Instagram 앱 ID로 교체하고(앱 대시보드 > 제품 > Instagram > 기본 디스플레이 > Instagram 앱 ID 필드에서) {redirect-uri}는 2단계에서 제공한 웹사이트 URL("유효한 OAuth 리디렉션 URI")로 교체 URL은 정확히 똑같아야 한다.
scope는 가져올 데이터의 범위, response_type은 해당 코드 요청하고 나면 반환받을 '인증code'
ex
https://api.instagram.com/oauth/authorize
?client_id=684477648739411
&redirect_uri=https://socialsizzle.herokuapp.com/auth/
&scope=user_profile,user_media
&response_type=code
curl -X POST \
https://api.instagram.com/oauth/access_token \
-F client_id={app-id} \
-F client_secret={app-secret} \
-F grant_type=authorization_code \
-F redirect_uri={redirect-uri} \
-F code={code}
curl -X POST \
https://api.instagram.com/oauth/access_token \
-F client_id=684477648739411 \
-F client_secret=eb8c7... \
-F grant_type=authorization_code \
-F redirect_uri=https://socialsizzle.herokuapp.com/auth/ \
-F code=AQDp3TtBQQ...
{
"access_token": "IGQVJ...",
"user_id": 17841405793187218
}
curl -i -X GET "https://graph.instagram.com/access_token
?grant_type=ig_exchange_token
&client_secret={instagram-app-secret}
&access_token={short-lived-access-token}"
{
"access_token":"{long-lived-user-access-token}",
"token_type": "bearer",
"expires_in": 5183944 // Number of seconds until token expires
}
curl -i -X GET "https://graph.instagram.com/refresh_access_token
?grant_type=ig_refresh_token
&access_token={long-lived-access-token}"
{
"access_token":"{long-lived-user-access-token}",
"token_type": "bearer",
"expires_in": 5183944 // Number of seconds until token expires
}
GET /me/media?fields={fields}&access_token={access-token}
fields에 어떤 data를 받을지 작성하기만 하면 된다.
fields : 가져올 미디어
ex
curl -X GET \ 'https://graph.instagram.com/17895695668004550?fields=id,media_type,media_url,username,timestamp&access_token=IGQVJ...'
{ "id": "17895695668004550", "media_type": "IMAGE", "media_url": "https://fb-s-b-a.akamaihd.net/...", "username": "jayposiris" "timestamp": "2017-08-31T18:10:00+0000" }
GET /{media-id}/children?fields={fields}&access_token={access-token}
연동 버튼을 누르면,
로그인 화면이 뜬다.
로그인하면 연동에 대한 허용 여부를 묻는다.
안녕하세요 API 연동 한달동안 해보고있는데 안되네요 ㅠ 설명해주신 설정 다 해보고 사이트에 페이스북로그인만들어서 하는데 안되요 ㅠㅠ 혹시 코드좀 공유해주실수 있을까요 부탁드려요