Jay-Flower (7) 통신부분 처리하자
Search
🌸

Jay-Flower (7) 통신부분 처리하자

게시 날짜
2021/09/25 05:53
태그
프로젝트
안드로이드
코틀린
참여자
Jay
Jenny
Jason

유저의 포토스트림 받아오기

우선 포토스트림을 받아오려면 NSID라는 유저 아이디가 필요하다. shutterbug_uk2012라는 유저를 검색해보자

NSID 받기 - getUserNSID()

(GET) https://www.flickr.com/services/rest?nojsoncallback=1&format=json&method=flickr.people.findByUsername&api_key=<API키>&username=shutterbug_uk2012
Plain Text
복사
{ "user": { "id": "86832534@N03", "nsid": "86832534@N03", "username": { "_content": "shutterbug_uk2012" } }, "stat": "ok" }
JSON
복사
이런 데이터가 내려온다. Android Project에 data class와 통신 부분을 추가하자

Photo 가져오기 - getUserPhotoList()

받아온 id를 가지고 사진을 받자
https://www.flickr.com/services/rest?nojsoncallback=1&format=json&method=flickr.people.getPhotos&api_key=<API 키>&user_id=86832534@N03
Kotlin
복사
{ "photos": { "page": 1, "pages": 1, "perpage": 100, "total": 49, "photo": [ { "id": "51298709139", "owner": "86832534@N03", "secret": "6af0f7313f", "server": "65535", "farm": 66, "title": "solitude", "ispublic": 1, "isfriend": 0, "isfamily": 0 }, { "id": "51250875038", "owner": "86832534@N03", "secret": "6d3ddfd9f5", "server": "65535", "farm": 66, "title": "heat", "ispublic": 1, "isfriend": 0, "isfamily": 0 }, { "id": "51204137576", "owner": "86832534@N03", "secret": "1059311984", "server": "65535", "farm": 66, "title": "endless", "ispublic": 1, "isfriend": 0, "isfamily": 0 }, { "id": "51147367807", "owner": "86832534@N03", "secret": "2c47740727", "server": "65535", "farm": 66, "title": "flow", "ispublic": 1, "isfriend": 0, "isfamily": 0 }, { "id": "29558462534", "owner": "86832534@N03", "secret": "7ac1239618", "server": "8554", "farm": 9, "title": "Ethereal (Explored)", "ispublic": 1, "isfriend": 0, "isfamily": 0 } ] }, "stat": "ok" }
Kotlin
복사
이렇게 내려오는걸 볼 수 있다.
이 데이터로 어떻게 url을 만드는지 찾아보자.
"https://farm${photo.farm}.staticflickr.com/${photo.server}/${photo.id}_${photo.secret}.jpg"
Kotlin
복사
이렇게 받아오면 된다.
예시로 가져왔다.
https://farm66.staticflickr.com/65535/51298709139_6af0f7313f.jpg
Kotlin
복사
잘 가져와진다.
유저를 검색해서 사진을 받아오는건 지금까지의 내용으로 가능하다.
https://www.flickr.com/services/rest?nojsoncallback=1&format=json&method=flickr.people.getInfo&api_key=<API 키>&user_id=86832534@N03
Kotlin
복사
위와 같이 보내면 아래와 같이 리턴해준다.
{ "person": { "id": "86832534@N03", "nsid": "86832534@N03", "ispro": 1, "can_buy_pro": 0, "iconserver": "65535", "iconfarm": 66, "path_alias": null, "has_stats": 0, "pro_badge": "legacy", "expire": "0", "username": { "_content": "shutterbug_uk2012" }, "realname": { "_content": "Paul" }, "location": { "_content": "United Kingdom" }, "timezone": { "label": "GMT: Dublin, Edinburgh, Lisbon, London", "offset": "+00:00", "timezone_id": "Europe/London" }, "description": { "_content": "The only programme I’m likely to get on is the *******news. - Withnail." }, "photosurl": { "_content": "https://www.flickr.com/photos/86832534@N03/" }, "profileurl": { "_content": "https://www.flickr.com/people/86832534@N03/" }, "mobileurl": { "_content": "https://m.flickr.com/photostream.gne?id=86809480" }, "photos": { "firstdatetaken": { "_content": "2016-09-04 19:28:58" }, "firstdate": { "_content": "1475924844" }, "count": { "_content": 50 } }, "has_adfree": 0, "has_free_standard_shipping": 0, "has_free_educational_resources": 0 }, "stat": "ok" }
Kotlin
복사
받아온 데이터를 이용해 아래처럼 url을 만든다.
"https://farm${person.iconfarm}.staticflickr.com/${person.iconserver}/buddyicons/${person.nsid}_r.jpg"
Kotlin
복사
https://farm66.staticflickr.com/65535/buddyicons/86832534@N03_r.jpg
Kotlin
복사
Request
https://www.flickr.com/services/rest?nojsoncallback=1&format=json&method=flickr.photos.getInfo&api_key=<API 키>&photo_id=51298709139
Kotlin
복사
Response
{ "photo": { "id": "51298709139", "secret": "6af0f7313f", "server": "65535", "farm": 66, "dateuploaded": "1625743866", "isfavorite": 0, "license": "0", "safety_level": "0", "rotation": 0, "owner": { "nsid": "86832534@N03", "username": "shutterbug_uk2012", "realname": "Paul", "location": "United Kingdom", "iconserver": "65535", "iconfarm": 66, "path_alias": null }, "title": { "_content": "solitude" }, "description": { "_content": "The last of my series of fishing huts from the banks of the Gironde. I shot here for 3 days, slowly moving along the shoreline but often returning to this particular location. There’s something I love about the structure of this carrelet and because it’s off the beaten track, it was easy to take my time, empty my mind and shoot in complete solitude. \n\nI hope that you’re all having a lovely week out there in Flickrland. \n" }, "visibility": { "ispublic": 1, "isfriend": 0, "isfamily": 0 }, "dates": { "posted": "1625743866", "taken": "2019-09-03 05:24:00", "takengranularity": "0", "takenunknown": "0", "lastupdate": "1631249930" }, "views": "114816", "editability": { "cancomment": 0, "canaddmeta": 0 }, "publiceditability": { "cancomment": 1, "canaddmeta": 0 }, "usage": { "candownload": 0, "canblog": 0, "canprint": 0, "canshare": 0 }, "comments": { "_content": "231" }, "notes": { "note": [] }, "people": { "haspeople": 0 }, "tags": { "tag": [ { "id": "86809480-51298709139-487", "author": "86832534@N03", "authorname": "shutterbug_uk2012", "raw": "FRANCE", "_content": "france", "machine_tag": 0 }, { "id": "86809480-51298709139-545", "author": "86832534@N03", "authorname": "shutterbug_uk2012", "raw": "COLOUR", "_content": "colour", "machine_tag": 0 }, { "id": "86809480-51298709139-7254", "author": "86832534@N03", "authorname": "shutterbug_uk2012", "raw": "SMOOTH", "_content": "smooth", "machine_tag": 0 }, { "id": "86809480-51298709139-3297", "author": "86832534@N03", "authorname": "shutterbug_uk2012", "raw": "LONG", "_content": "long", "machine_tag": 0 }, { "id": "86809480-51298709139-3298", "author": "86832534@N03", "authorname": "shutterbug_uk2012", "raw": "EXPOSURE", "_content": "exposure", "machine_tag": 0 }, { "id": "86809480-51298709139-1414", "author": "86832534@N03", "authorname": "shutterbug_uk2012", "raw": "REFLECTIONS", "_content": "reflections", "machine_tag": 0 } ] }, "urls": { "url": [ { "type": "photopage", "_content": "https://www.flickr.com/photos/86832534@N03/51298709139/" } ] }, "media": "photo" }, "stat": "ok" }
Kotlin
복사
Request
https://www.flickr.com/services/rest?nojsoncallback=1&format=json&method=flickr.photos.comments.getList&api_key=<API 키>&photo_id=51298709139
Kotlin
복사
Response
{ "comments": { "photo_id": "51298709139", "comment": [ { "id": "86809480-51298709139-72157719512996379", "author": "156297092@N07", "author_is_deleted": 0, "authorname": "_Oh my god Greta_", "iconserver": "65535", "iconfarm": 66, "datecreate": "1625744044", "permalink": "https://www.flickr.com/photos/86832534@N03/51298709139/#comment72157719512996379", "path_alias": null, "realname": "Greta", "_content": "Sublime work and series! I'm happy, that I'm at home and have the joy to look the large view! Thanks for share with us dear Paul :-)" }, { "id": "86809480-51298709139-72157719532160932", "author": "108577525@N06", "author_is_deleted": 0, "authorname": "Stranded47", "iconserver": "451", "iconfarm": 1, "datecreate": "1625916127", "permalink": "https://www.flickr.com/photos/86832534@N03/51298709139/#comment72157719532160932", "path_alias": "blackbeck97", "realname": "", "_content": "The ultimate 'lockdown' property! Lovely image." }, { "id": "86809480-51298709139-72157719574653120", "author": "75894761@N08", "author_is_deleted": 0, "authorname": "GillK2012", "iconserver": "3829", "iconfarm": 4, "datecreate": "1625918284", "permalink": "https://www.flickr.com/photos/86832534@N03/51298709139/#comment72157719574653120", "path_alias": "gill-was-here", "realname": "", "_content": "Love these fishing hut images of yours Paul, their quirkiness against the beautiful mirror-like water is quite magical! Definitely one for the wall, although not yours, I’d like it on mine 👍😂" }, { "id": "86809480-51298709139-72157719801890654", "author": "167792125@N05", "author_is_deleted": 0, "authorname": "◞hēll໐ ຟ໐rl໓", "iconserver": "65535", "iconfarm": 66, "datecreate": "1631249930", "permalink": "https://www.flickr.com/photos/86832534@N03/51298709139/#comment72157719801890654", "path_alias": "eng-see-the-world", "realname": "📷 PɧყƖƖıʂ", "_content": "How are you, Paul?" } ] }, "stat": "ok" }
Kotlin
복사