Mandarin Drama website/API


**

**
https://www.google.com/search?q=duonao&rlz=1C1SQJL_enUS817US817&oq=duonao&aqs=chrome..69i57j69i59j0l4.2466j0j7&sourceid=chrome&ie=UTF-8


**

**
https://www.jianshu.com/p/a7e51129b042

[Android] Douban Movie API Guide

96
Tnnowu 
2018.02.01 01:20* Word Count 859 Read 4128 Comment 8 
Douban is a well-known section, and his rating is very representative. We use the Douban Movie API to capture data from movies. This article should be the latest and most comprehensive API guide for the entire network.

First, Douban Movie API official document

Calling a third-party APIinterface first looks at an article written by someone else, but instead reads the official interface document , which is the latest and most comprehensive.
From this we can read that the APIinterface document is divided into 4 major parts, 14 small parts:

Second, parse the API interface to obtain server data

Network request to use RxJava2Retrofit2, if the network request does not understand, you can see my other article: Network Request Framework - Retrofit
Off-topic: V2 version API permissions are divided into 3 categories: public, advanced, and business, so some interface data is not available.
Movie entry information
/**
 * 电影条目信息
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * city:所在城市,例如北京、上海等
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:http://api.douban.com/v2/movie/subject/26004132?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:http://api.douban.com/v2/movie/subject/26004132?apikey=0b2bdeda43b5688921839c8ecb20399b&city=%E5%8C%97%E4%BA%AC&client=&udid=
 */
@GET("subject/{movieId}")
Observable<MovieSubjectInfoBean> getMovieSubjectInfo(@Path("movieId") String movieId,
                                                     @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 5.4
原名: The Maze Runner: The Death Cure
电影海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2508618114.jpg
年代: 2018
短评评分: 2
短评用户名: 舒农
短评内容: 删掉一个小时会更好。第三幕长到整部电影仿佛3个小时。
电影 ID: 26004132
上映日期: 2018-01-26
电影中文名: 移动迷宫3:死亡解药
语言: 英语
编剧头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1513398561.53.jpg
编剧英文名: T.S. Nowlin
编剧中文名: T·S·诺林
编剧 ID: 1342902
标签: 科幻
片长: 142分钟
影片类型: 动作, 科幻, 冒险
预告片图片: http://img3.doubanio.com/img/trailer/medium/2512246766.jpg?1517382304
预告片影片: http://vt1.doubanio.com/201802010046/aa610896c80023bcc278b67ef9daf775/view/movie/M/302260927.mp4
花絮图片: http://img7.doubanio.com/img/trailer/medium/2511634245.jpg?1516872258
花絮影片: http://vt1.doubanio.com/201802010046/3b1390d988dbf4e79be7ab35c770a592/view/movie/M/302260637.mp4
片段图片: http://img3.doubanio.com/img/trailer/medium/2511459538.jpg?1516696141
片段影片: http://vt1.doubanio.com/201802010046/afa09007e76a52890f30a610a1e1c3f5/view/movie/M/302260558.mp4
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p53688.jpg
主演英文名: Dylan O'Brien
主演中文名: 迪伦·奥布莱恩
主演 ID: 1314963
制片国家/地区: 美国
大陆上映日期: 2018-01-26
电影剧照: http://img7.doubanio.com/view/photo/photo/public/p2511621790.jpg
简介: 《移动迷宫3》作为系列最终章,沿袭系列一贯以来的劲爆动作戏和快节奏跑酷风,主要讲述迪伦·奥布莱恩饰演的托马斯率领的好莱坞“跑男团”在经历了迷宫逃脱和末日丧尸的生死考验后,终于迎来最后的正邪较量。
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1417887954.94.jpg
导演英文名: Wes Ball
导演中文名: 韦斯·鲍尔
导演 ID: 1332723
影评评分: 2
影评标题: 导演的脑回路就是个迷宫,走进去就出不来了
影评用户名: 凌睿
影评内容: 整个系列都没有移动,为什么在片名里写个“移动”?你考虑过联通和电信的感受吗? 《移动迷宫1》没有移动,好歹还有迷宫。 《移动迷宫2》没有移动,没有迷宫,好歹还很二。 《移动迷宫3:死亡解药》是移动、迷宫...
onComplete: 
Movie entry stills
/**
 * 电影条目剧照
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * start:分页使用,表示第几页
 * count:分页使用,表示数量
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/subject/26004132/photos?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/subject/26004132/photos?apikey=0b2bdeda43b5688921839c8ecb20399b&start=0&count=100&client=&udid=
 */
@GET("subject/{movieId}/photos")
Observable<MovieSubjectPhotosBean> getMovieSubjectPhotos(@Path("movieId") String movieId,
                                                         @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
电影剧照: http://img7.doubanio.com/view/photo/photo/public/p2511051532.jpg
评分: 5.4
影片类型: 动作, 科幻, 冒险
影片标题: 移动迷宫3:死亡解药
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p53688.jpg
主演英文名: Dylan O'Brien
主演中文名: 迪伦·奥布莱恩
主演 ID: 1314963
片长: 142分钟
大陆上映日期: 2018-01-26
原名: The Maze Runner: The Death Cure
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1417887954.94.jpg
导演英文名: Wes Ball
导演中文名: 韦斯·鲍尔
导演 ID: 1332723
onNext: 2018-01-26(美国), 2018-01-26(中国大陆)
年代: 2018
电影海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2508618114.jpg
电影 ID: 26004132
onComplete: 
Movie item long comment
/**
 * 电影条目长评
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * start:分页使用,表示第几页
 * count:分页使用,表示数量
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/subject/26004132/reviews?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/subject/26004132/reviews?apikey=0b2bdeda43b5688921839c8ecb20399b&start=0&count=20&client=&udid=
 */
@GET("subject/{movieId}/reviews")
Observable<MovieSubjectReviewsBean> getMovieSubjectReviews(@Path("movieId") String movieId,
                                                           @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 2
用户名: 凌睿
评论标题: 导演的脑回路就是个迷宫,走进去就出不来了
评论简介: 整个系列都没有移动,为什么在片名里写个“移动”?你考虑过联通和电信的感受吗? 《移动迷宫1》没有移动,好歹还有迷宫。 《移动迷宫2》没有移动,没有迷宫,好歹还很二。 《移动迷宫3:死亡解药》是移动、迷宫...
评论内容: 整个系列都没有移动,为什么在片名里写个“移动”?你考虑过联通和电信的感受吗?《移动迷宫1》没有移动,好歹还有迷宫。《移动迷宫2》没有移动,没有迷宫,好歹还很二。《移动迷宫3:死亡解药》是移动、迷宫、解药、二、小三通通都没有了,所以我只能选择死亡。。。
影片评分: 5.4
影片类型: 动作, 科幻, 冒险
影片标题: 移动迷宫3:死亡解药
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p53688.jpg
主演英文名: Dylan O'Brien
主演中文名: 迪伦·奥布莱恩
主演 ID: 1314963
片长: 142分钟
大陆上映时间: 2018-01-26
原名: The Maze Runner: The Death Cure
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1417887954.94.jpg
导演英文名: Wes Ball
导演中文名: 韦斯·鲍尔
导演 ID: 1332723
上映日期: 2018-01-26(美国), 2018-01-26(中国大陆)
年代: 2018
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2508618114.jpg
影片 ID: 26004132
onComplete: 
Movie item short comment
/**
 * 电影条目短评
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * count:分页使用,表示数量
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/subject/26004132/comments?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/subject/26004132/comments?apikey=0b2bdeda43b5688921839c8ecb20399b&count=20&client=&udid=
 */
@GET("subject/{movieId}/comments")
Observable<MovieSubjectCommentsBean> getMovieSubjectComments(@Path("movieId") String movieId,
                                                             @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 2
用户名: 瓦力
评论内容: 1>2>3,场面比2升级了,迷宫?不存在的。槽点数量系列之最。请问:什么样的炸弹能瞬间炸塌百米高的城墙?什么样的人连人带车从百米高处坠落竟能毫发无伤?什么样的隔离玻璃一砸就碎?号称安保严密的据点被男主一行人轻易潜入且来去自如,结局混战毁一座城为救几十人死数万人,这是反乌托邦还是反人类?
影片评分: 5.4
影片类型: 动作, 科幻, 冒险
影片标题: 移动迷宫3:死亡解药
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p53688.jpg
主演英文名: Dylan O'Brien
主演中文名: 迪伦·奥布莱恩
主演 ID: 1314963
片长: 142分钟
大陆上映日期: 2018-01-26
原名: The Maze Runner: The Death Cure
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1417887954.94.jpg
导演英文名: Wes Ball
导演中文名: 韦斯·鲍尔
导演 ID: 1332723
上映日期: 2018-01-26(美国), 2018-01-26(中国大陆)
年代: 2018
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2508618114.jpg
影片 ID: 26004132
onComplete: 
Shadow entry information
/**
 * 影人条目信息
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 *
 * 全:https://api.douban.com/v2/movie/celebrity/1044707?apikey=0b2bdeda43b5688921839c8ecb20399b
 */
@GET("celebrity/{celebrityId}")
Observable<MovieCelebrityInfoBean> getMovieCelebrityInfo(@Path("celebrityId") String celebrityId,
                                                         @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
中文名: 道恩·强森
英文名: Dwayne Johnson
性别: 男
职业: 演员, 制片, 配音
影人头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p196.jpg
简介: “岩石”(The Rock)本名叫德威恩·约翰逊(Dwayne Johnson),曾是世界摔角联联合会的冠军和明星人物。在体育界成名后,他的触角逐渐伸向影视圈,先是参加了一些电视节目的录制,然后又在连续剧中露过几面。凭着健硕的身材、英俊的相貌和广泛的知名度,“岩石”很快就在这个圈子里得到了不错的口碑。岩石, 197252日 生于美国加州的海沃德,是他们家第3代摔角手,父亲是著名摔角健将洛奇·约翰逊,爷爷彼得·麦维亚也是摔角界的传奇人物。耳闻目染之下,他从小即掌握了一些极佳的摔角技巧。父亲从小对他要求严格,希望长大培养出新一代的摔交手。岩石从8岁时就开始练拳,14岁走进健身房,成年后练就了一副好的体格,他的成功应该归功于他老爸的鼓励和自己的毅力、信心。
影人剧照: http://img3.doubanio.com/view/photo/photo/public/p2207562906.jpg
出生日期: 1972-05-02
更多中文名: 巨石强森, 德威恩·道格拉斯·约翰逊, 唐尼·约翰逊, 岩石, 巨石, 狄维庄逊(港)
出生地: 美国,加利福尼亚,海沃德
星座: 金牛座
影人 ID: 1044707
作品担任角色: 演员
作品评分: 9.2
作品类型: 喜剧, 音乐
作品名: 周六夜现场 第一季
作品主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1408438010.98.jpg
作品主演英文名: Don Pardo
作品主演中文名: 唐·帕尔多
作品主演 ID: 1126676
作品片长: 90分钟
作品大陆上映日期: 
作品原名: Saturday Night Live
作品类别: tv
作品导演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p48858.jpg
作品导演英文名: Lorne Michaels
作品导演中文名: 洛恩·迈克尔斯
作品导演 ID: 1041290
作品上映日期: 1975-10-11(美国)
作品年代: 1975
作品海报图: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2503284915.jpg
作品 ID: 1887452
onComplete: 
Film crew stills
/**
 * 影人剧照
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 *
 * 全:https://api.douban.com/v2/movie/celebrity/1044707/photos?apikey=0b2bdeda43b5688921839c8ecb20399b
 */
@GET("celebrity/{celebrityId}/photos")
Observable<MovieCelebrityPhotosBean> getMovieCelebrityPhotos(@Path("celebrityId") String celebrityId,
                                                             @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
影人剧照: http://img3.doubanio.com/view/photo/photo/public/p2207562906.jpg
影人头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p196.jpg
影人英文名: Dwayne Johnson
影人中文名: 道恩·强森
影人 ID: 1044707
onComplete: 
Filmmaker works
/**
 * 影人作品
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 *
 * 全:https://api.douban.com/v2/movie/celebrity/1044707/works?apikey=0b2bdeda43b5688921839c8ecb20399b
 */
@GET("celebrity/{celebrityId}/works")
Observable<MovieCelebrityWorksBean> getMovieCelebrityWorks(@Path("celebrityId") String celebrityId,
                                                           @Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
作品担任角色: 演员
作品评分: 0
作品类型: 动作, 冒险
作品名: 地心历险记4
作品主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p196.jpg
作品主演英文名: Dwayne Johnson
作品主演中文名: 道恩·强森
作品主演 ID: 1044707
作品片长: 
作品大陆上映日期: 
作品原名: Journey to the Center of the Earth 4
作品类别: movie
作品上映日期: 
作品年代: 2020
作品海报图: http://img3.doubanio.com/f/movie/5081e011b4b06f1a8c3735122b38e781bd852ab6/pics/movie/movie_default_medium.png
作品 ID: 25963336
onComplete: 
Movie search
/**
 * 电影搜索
 *
 * q:字符串
 * tag:标签
 * start:分页使用,表示第几页
 * count:分页使用,表示数量
 *
 * 全:https://api.douban.com/v2/movie/search?q=周杰伦&apikey=0b2bdeda43b5688921839c8ecb20399b&start=0&count=10
 * 全:https://api.douban.com/v2/movie/search?tag=喜剧&apikey=0b2bdeda43b5688921839c8ecb20399b&start=0&count=10
 */
// 根据字段搜索
@GET("search")
Observable<MovieSearchByQueryBean> getMovieSearchByQuery(@Query("q") String q,
                                                         @Query("apikey") String apikey,
                                                         @Query("start") int start,
                                                         @Query("count") int count);

// 根据标签搜索
@GET("search")
Observable<MovieSearchByTagBean> getMovieSearchByTag(@Query("tag") String tag,
                                                     @Query("apikey") String apikey,
                                                     @Query("start") int start,
                                                     @Query("count") int count);
LogLog:
onSubscribe: 
onNext: 
评分: 7.6
影片类型: 剧情, 奇幻, 音乐
影片标题: 不能说的秘密
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p18606.jpg
主演英文名: Jay Chou
主演中文名: 周杰伦
主演 ID: 1048000
片长: 101 分钟
大陆上映日期: 2007-07-31
原名: 不能說的·祕密
类型: movie
导演英文名: Jay Chou
导演中文名: 周杰伦
上映日期: 2007-07-27(台湾), 2007-07-31(中国大陆)
年代: 2007
影片海报: http://img3.doubanio.com/view/photo/s_ratio_poster/public/p917037900.jpg
影片 ID: 2124724
onComplete: 
onSubscribe: 
onNext: 
评分: 9.2
影片类型: 剧情, 喜剧, 爱情
影片标题: 三傻大闹宝莱坞
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p13628.jpg
主演英文名: Aamir Khan
主演中文名: 阿米尔·汗
主演 ID: 1031931
片长: 171分钟(印度)
大陆上映日期: 2011-12-08
原名: 3 Idiots
类型: movie
导演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p16549.jpg
导演英文名: Rajkumar Hirani
导演中文名: 拉吉库马尔·希拉尼
导演 ID: 1286677
上映日期: 2009-12-25(印度), 2011-12-08(中国大陆)
年代: 2009
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p579729551.jpg
影片 ID: 3793023
onComplete: 
Hot
/**
 * 正在热映
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * city:所在城市,例如北京、上海等
 * start:分页使用,表示第几页
 * count:分页使用,表示数量
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/in_theaters?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/in_theaters?apikey=0b2bdeda43b5688921839c8ecb20399b&city=%E5%8C%97%E4%BA%AC&start=0&count=100&client=&udid=
 */
@GET("in_theaters")
Observable<MovieInTheatersBean> getMovieInTheaters(@Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 7.4
影片类型: 剧情, 传记, 歌舞
影片标题: 马戏之王
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p22036.jpg
主演英文名: Hugh Jackman
主演中文名: 休·杰克曼
主演 ID: 1010508
片长: 105分钟, 106分钟(中国大陆)
大陆上映日期: 2018-02-01
原名: The Greatest Showman
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1498127697.1.jpg
导演英文名: Michael Gracey
导演中文名: 迈克尔·格雷西
导演 ID: 1344735
上映日期: 2017-12-20(美国), 2018-02-01(中国大陆)
年代: 2017
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2511346392.jpg
影片 ID: 3914513
onComplete: 
coming soon
/**
 * 即将上映
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * city:所在城市,例如北京、上海等
 * start:分页使用,表示第几页
 * count:分页使用,表示数量
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/coming_soon?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/coming_soon?apikey=0b2bdeda43b5688921839c8ecb20399b&city=%E5%8C%97%E4%BA%AC&start=0&count=100&client=&udid=
 */
@GET("coming_soon")
Observable<MovieComingSoonBean> getMovieComingSoon(@Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 7.1
影片类型: 喜剧, 惊悚, 恐怖
影片标题: 忌日快乐
主演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1510538799.61.jpg
主演英文名: Jessica Rothe
主演中文名: 杰西卡·罗德
主演 ID: 1325899
片长: 96分钟
大陆上映日期: 2018-02-02
原名: Happy Death Day
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p18083.jpg
导演英文名: Christopher Landon
导演中文名: 克里斯托弗·兰登
导演 ID: 1032310
上映日期: 2017-10-13(美国), 2018-02-02(中国大陆)
年代: 2017
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2510057340.jpg
影片 ID: 27027913
onComplete: 
Top250
/**
 * Top250
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * city:所在城市,例如北京、上海等
 * start:分页使用,表示第几页
 * count:分页使用,表示数量
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/top250?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/top250?apikey=0b2bdeda43b5688921839c8ecb20399b&city=%E5%8C%97%E4%BA%AC&start=0&count=100&client=&udid=
 */
@GET("top250")
Observable<MovieTop250Bean> getMovieTop250(@Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 9.6
影片类型: 犯罪, 剧情
影片标题: 肖申克的救赎
主演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p17525.jpg
主演英文名: Tim Robbins
主演中文名: 蒂姆·罗宾斯
主演 ID: 1054521
片长: 142 分钟
大陆上映日期: 
原名: The Shawshank Redemption
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p230.jpg
导演英文名: Frank Darabont
导演中文名: 弗兰克·德拉邦特
导演 ID: 1047973
上映日期: 1994-09-10(多伦多电影节), 1994-10-14(美国)
年代: 1994
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p480747492.jpg
影片 ID: 1292052
onComplete: 
Word of mouth
/**
 * 口碑榜
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * city:所在城市,例如北京、上海等
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/weekly?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/weekly?apikey=0b2bdeda43b5688921839c8ecb20399b&city=%E5%8C%97%E4%BA%AC&client=&udid=
 */
@GET("weekly")
Observable<MovieWeeklyBean> getMovieWeekly(@Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 8.6
影片类型: 剧情, 儿童, 家庭
影片标题: 奇迹男孩
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1456737567.18.jpg
主演英文名: Jacob Tremblay
主演中文名: 雅各布·特伦布莱
主演 ID: 1332866
片长: 113分钟, 114分钟(中国大陆)
大陆上映日期: 2018-01-19
原名: Wonder
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p57551.jpg
导演英文名: Stephen Chbosky
导演中文名: 斯蒂芬·卓博斯基
导演 ID: 1070754
上映日期: 2017-11-17(美国), 2018-01-19(中国大陆)
年代: 2017
影片海报: http://img3.doubanio.com/view/photo/s_ratio_poster/public/p2507709428.jpg
影片 ID: 26787574
onComplete: 
North American box office list
/**
 * 北美票房榜
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/us_box?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/us_box?apikey=0b2bdeda43b5688921839c8ecb20399b&client=&udid=
 */
@GET("us_box")
Observable<MovieUsBoxBean> getMovieUsBox(@Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
日期: 126日 - 128
排行: 1
评分: 5.4
影片类型: 动作, 科幻, 冒险
影片标题: 移动迷宫3:死亡解药
主演头像: http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p53688.jpg
主演英文名: Dylan O'Brien
主演中文名: 迪伦·奥布莱恩
主演 ID: 1314963
片长: 142分钟
大陆上映日期: 2018-01-26
原名: The Maze Runner: The Death Cure
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1417887954.94.jpg
导演英文名: Wes Ball
导演中文名: 韦斯·鲍尔
导演 ID: 1332723
上映日期: 2018-01-26(美国), 2018-01-26(中国大陆)
年代: 2018
影片海报: http://img7.doubanio.com/view/photo/s_ratio_poster/public/p2508618114.jpg
影片 ID: 26004132
onComplete:
New film list
/**
 * 新片榜
 *
 * apikey:固定值 0b2bdeda43b5688921839c8ecb20399b
 * client:客户端信息。可为空
 * udid:用户 id。可为空
 *
 * 简:https://api.douban.com/v2/movie/new_movies?apikey=0b2bdeda43b5688921839c8ecb20399b
 * 全:https://api.douban.com/v2/movie/new_movies?apikey=0b2bdeda43b5688921839c8ecb20399b&client=&udid=
 */
@GET("new_movies")
Observable<MovieNewMoviesBean> getMovieNewMovies(@Query("apikey") String apikey);
LogLog:
onSubscribe: 
onNext: 
评分: 8.7
影片类型: 剧情, 犯罪
影片标题: 三块广告牌
主演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1436865941.42.jpg
主演英文名: Frances McDormand
主演中文名: 弗兰西斯·麦克多蒙德
主演 ID: 1010548
片长: 115分钟
大陆上映日期: 2018-03-02
原名: Three Billboards Outside Ebbing, Missouri
导演头像: http://img7.doubanio.com/view/celebrity/s_ratio_celebrity/public/p3143.jpg
导演英文名: Martin McDonagh
导演中文名: 马丁·麦克唐纳
导演 ID: 1000304
上映日期: 2017-09-04(威尼斯电影节), 2017-11-10(美国), 2018-03-02(中国大陆)
年代: 2017
影片海报: http://img3.doubanio.com/view/photo/s_ratio_poster/public/p2510081688.jpg
影片 ID: 26611804
onComplete: 
The sample project code has been uploaded to GitHub, if the article is helpful to you, please like, thank you. 
https://github.com/cnwutianhao/DoubanMovie
A warm afternoon tea, refreshing and helping me create better quality code~
Appreciate support
     Android development
    Web note ad 1

    Sign in to post a comment

    peter_RD_nj
    4th floor · 2018.10.11 18:59
    The official service platform hangs, how does the landlord go up?

    peter_RD_nj
    3rd floor · 2018.10.11 18:57
    Looking for a long time, thank the landlord

    After thinking, I think twice
    2nd floor · 2018.02.01 21:09
    Hello, now, Douban apikey is not open to individuals, how did you apply?
    Tnnowu :
     Used by others to share the KEY
    2018.02.01 21:34  Reply
     @tnnowu turns out to be like this
    2018.02.02 00:41  Reply
     What is the limit on the number of calls to your Douban api?
    2018.02.08 04:18  Reply
     Add a new comment There are 2 more comments to view
    Recommended readingmore exciting content
    [Emotion] Hand in hand (72)
    Yanan pushed the door of the small room and saw Xiaoying was stuffing clothes into a blue travel bag. She hurriedly walked over to hold the hand of Xiaoying, and at the same time took her bag to the side. She turned and said to Xiaoying: "If you say your sentence, you can't stand it, you really have to leave home!" Nan deliberately blamed the small shadow, while pushing the small shadow on the bed. "My brother doesn't understand me at all! You don't know how hard he is to talk! It's him who told me to go! He let me roll!" Xiaoying gased and grinned. "He's not in the air! It's all the words, just say what you don't like to listen to. Not that I am facing your brother, heaven and earth conscience, your brother is all for you, you should understand that your brother is afraid that you will be deceived. "I am not a child, not someone else can lie to the sugar! I have a few hearts!" Xiaoying continued to pout. "College students are smarter than you, at least more books than you read, and a wide range of knowledge. Every year, not only are college students cheated to the mountains...

     Come to Hui
    Apple Enterprise Signature Platform - the platform of choice for high-end users
    Apple enterprise certificate signature iosAPP signature package distribution hosting platform "internal test expert" Apple enterprise signature, internal measurement distribution, one step in place. High-end users preferred, safe and reliable operation, unlimited installation download. Long-term use, free update. We use word of mouth quality Serve for trust. "Internal Experts" is an in-app testing and hosting platform for iOS and Android developers. It is designed to solve the cumbersome and inefficient problems developers use when distributing applications to internal users. The SDK is more developed by developers. The feedback of the internal test brings great convenience. "Internal Experts" mainly provide testing and online services for iOS App, Android App. The main business is iOS online pre-audit, iOS audit acceleration, iOS corporate signature, compatibility testing and security testing services. Team with 10 years of testing experience, full manual service,...

     Onkyo Information
    My plan for ten years
    ten years! Can be long or short. Time is like a gap. The 12-year-old himself is young and childish. The 22-year-old himself has matured and experienced the baptism of time. In the third year of junior high school, I studied hard and achieved excellent results. At that time, I was able to learn in my own eyes. Although simple, mechanical, rigid, I am very happy, it is a simple and simple pleasure. In high school for three years, I feel that my study has reached a peak. I think that in the past three years, I have gained knowledge and I have learned how to persist. In the end, I was admitted to my favorite major, although I am not very satisfied with my score. I graduated on July 1, 2018! I have obtained the certificate I should have. I graduated from Yunnan Normal University. I am a directed English teacher in Nujiang. Eight years of youth are fixed in my hometown, I became a rural female teacher. The next ten years can be long or short! Everything is in control. Actually these...

     142 hours Li Ping, Lishui
    What do you bring to fitness, writing, remembering words, reading books, speaking, getting up early?
    2018 read 50 books. Adhere to 500 days to practice speeches and voices. Persist in 500 1500 words per day. The Himalayas output learning content for 500 days. Stay healthy for the second 500 days a day. Stick to 500 words. I have to do these five things every day, and I will change myself after 500 days. Add a Himalayan output. Today is the 41st day of insisting on writing. Today is 545 days of fitness. Today is 45 days of insisting on the speech. Today is the 95th day of insisting on remembering words. Today is 294 days of insisting on reading. Today is the 21st day of sharing the Himalayas. Today is the sixth day of practicing the voice. Today is the first day of my early morning. After 500 days of planning, I completed my first fitness and I gained a lot. The biggest gain is my perseverance and my own persistence. I believe that I will stick to it, I will finish...

     My self-discipline life
    Cotton flower blossoming
    Friends, have you been to Xinjiang Aksu? Have you heard of Aksu's cotton? In October, no matter which ridge you walk to the Aksu area, you will be shocked by the endless sky-white cotton fields. The author is located in a Xinjiang agricultural group of about 15,000 people, also known as the oasis. It is about 600 square kilometers and has more than 250,000 mu of cultivated land. It is a typical area with a wide area. The 250,000 mu of land was rented by less than 5,000 people, and an average of 50 mu was to see a person who planted land. Friends in the mainland can't imagine how the land here is. I am in the edge of the Taklimakan Desert. There is no industry, only agriculture, and it is the production base of the treasury reserve cotton. The abundance of long-staple cotton is well-known throughout the country. A friend asked me: Can you cover the natural quilt? Of course, relying on mountains to eat mountains, producing more cotton, and covering a pure natural cotton is what it is. Produce here...

     Do you know if I love you?
    **

    **
    Download https://services.gradle.org/distributions/gradle-4.1-all.zip (85.90 MB)
    [ 96%] [ =====================================================> ] 83.01 MB
    Download https://services.gradle.org/distributions/gradle-4.1-all.zip succeeded, took 13 s 385 ms
    Unzipping ...

    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-core/3.0.1/gradle-core-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint/26.0.1/lint-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.0.1/builder-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/external/org-jetbrains/uast/26.0.1/uast-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-api/3.0.1/gradle-api-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/databinding/compilerCommon/3.0.1/compilerCommon-3.0.1.pom
    Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.1.3-2/kotlin-stdlib-1.1.3-2.pom
    Download https://jcenter.bintray.com/org/jacoco/org.jacoco.report/0.7.4.201502262128/org.jacoco.report-0.7.4.201502262128.pom
    Download https://jcenter.bintray.com/com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.pom
    Download https://jcenter.bintray.com/com/google/protobuf/protobuf-parent/3.0.0/protobuf-parent-3.0.0.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-test-api/3.0.1/builder-test-api-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/26.0.1/sdklib-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/26.0.1/sdk-common-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-model/3.0.1/builder-model-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/ddms/ddmlib/26.0.1/ddmlib-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/26.0.1/manifest-merger-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/26.0.1/protos-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/common/26.0.1/common-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/apksig/3.0.1/apksig-3.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/shared/26.0.1/shared-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/tracker/26.0.1/tracker-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-checks/26.0.1/lint-checks-26.0.1.pom
    Download https://jcenter.bintray.com/org/eclipse/jdt/core/compiler/ecj/4.6.1/ecj-4.6.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/databinding/baseLibrary/3.0.1/baseLibrary-3.0.1.pom
    Download https://jcenter.bintray.com/com/android/tools/annotations/24.5.0/annotations-24.5.0.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/dvlib/26.0.1/dvlib-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/repository/26.0.1/repository-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.pom
    Download https://jcenter.bintray.com/com/google/code/gson/gson/2.3/gson-2.3.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-api/26.0.1/lint-api-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/external/com-intellij/intellij-core/26.0.1/intellij-core-26.0.1.pom
    Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.3-2/kotlin-reflect-1.1.3-2.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/annotations/26.0.1/annotations-26.0.1.pom
    Download https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint/26.0.1/lint-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-core/3.0.1/gradle-core-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.0.1/builder-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-checks/26.0.1/lint-checks-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-api/26.0.1/lint-api-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/external/org-jetbrains/uast/26.0.1/uast-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-api/3.0.1/gradle-api-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/databinding/compilerCommon/3.0.1/compilerCommon-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/26.0.1/manifest-merger-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/26.0.1/sdk-common-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/26.0.1/sdklib-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/repository/26.0.1/repository-26.0.1.jar
    Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.3-2/kotlin-reflect-1.1.3-2.jar
    Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.1.3-2/kotlin-stdlib-1.1.3-2.jar
    Download https://jcenter.bintray.com/org/jacoco/org.jacoco.report/0.7.4.201502262128/org.jacoco.report-0.7.4.201502262128.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/tracker/26.0.1/tracker-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/shared/26.0.1/shared-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/26.0.1/protos-26.0.1.jar
    Download https://jcenter.bintray.com/com/google/protobuf/protobuf-java/3.0.0/protobuf-java-3.0.0.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-model/3.0.1/builder-model-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-test-api/3.0.1/builder-test-api-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/ddms/ddmlib/26.0.1/ddmlib-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/dvlib/26.0.1/dvlib-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/common/26.0.1/common-26.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/build/apksig/3.0.1/apksig-3.0.1.jar
    Download https://jcenter.bintray.com/org/eclipse/jdt/core/compiler/ecj/4.6.1/ecj-4.6.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/databinding/baseLibrary/3.0.1/baseLibrary-3.0.1.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/annotations/26.0.1/annotations-26.0.1.jar
    Download https://jcenter.bintray.com/com/google/code/gson/gson/2.3/gson-2.3.jar
    Download https://dl.google.com/dl/android/maven2/com/android/tools/external/com-intellij/intellij-core/26.0.1/intellij-core-26.0.1.jar

    FAILURE: Build failed with an exception.

    * What went wrong:
    A problem occurred configuring project ':app'.
    > Failed to find Build Tools revision 26.0.2

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    * Get more help at https://help.gradle.org

    CONFIGURE FAILED in 1m 15s
    Failed to find Build Tools revision 26.0.2
    Install Build Tools 26.0.2 and sync project

    **
    https://stackoverflow.com/questions/8103776/how-can-i-display-multiple-lines-of-text-on-a-button
    **

    **
    My button's layout_width set to match_parent.
    In order to display multi lines on the button, I tried:
    • insert '\n' into the text on button
    • set Singleline false set Maxlines to 2 or 3
    • convert html from Html.fromHtml
    Nothing worked. '\n' showed up as a small square on the button while showing single line of text.
    Does anybody have any idea why this is happening and how I can fix this?
    UPDATE: I just found out I was using custom button that has its own text drawing. That's the reason. Sorry for the confusion. I just punished myself by banging my head.

    3 Answers


    up vote75down voteaccepted
    If you're trying to add a new line in a layout XML file:
    Use &#10; (new line)
        android:text="Hi&#10;Hello"
    If you're trying to add a new line in code, just use '\n', same as in any other text.
    If you can't see the second line, it may be that your Button doesn't have enough height. IE, in my case, the layout containing the button had a fixed height that just happened to make my button perfectly display one line of text.

    I just tried and it worked:
    1) Define in ../res/values/strings.xml:
    <string name="multilines">Line1Line1\nLine2Line2</string>
    2) Refer it in the layout file:
    <Button
        android:id="@+id/btn_multilines"
        android:text="@string/multilines"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
    </Button>

    In case you want to do that programmaticaly you can use System.getProperty("line.separator")in the string to change lines. Like this:
    String mybuttontext=line1+System.getProperty("line.separator")+line2;
    and then set this String as buttons text
    **

    **

    **
    https://guides.codepath.com/android/consuming-apis-with-retrofit

    Consuming APIs with Retrofit

    Overview

    Retrofit is a type-safe REST client for Android, Java and Kotlin developed by Square. The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp. See this guide to understand how OkHttp works.
    This library makes downloading JSON or XML data from a web API fairly straightforward. Once the data is downloaded then it is parsed into a Plain Old Java Object (POJO) which must be defined for each "resource" in the response.

    Setup

    Make sure to require Internet permissions in your AndroidManifest.xml file:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.INTERNET" />
    </manifest>
    Add the following to your app/build.gradle file:
    dependencies {
        implementation 'com.google.code.gson:gson:2.8.5'
        implementation 'com.squareup.retrofit2:retrofit:2.4.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.4.0'  
    
    }
    Note: if you are upgrading from Retrofit 2 beta 1 or beta2, your package imports will need to be changed from import retrofit.XXXX to import retrofit2.XXXX. You will also need to update your OkHttp imports from import okhttp.XXXXto import okhttp3.XXXX because of the new OkHttp3 dependency:
    find . -name '*.java' -exec gsed -i 's/import retrofit\./import retrofit2./g' \{\} +
    find . -name '*.java' -exec gsed -i 's/import com.squareup.okhttp/import okhttp3/g' \{\} +
    If you intend to use RxJava with Retrofit 2, you will also need to include the RxJava adapter:
    dependencies {
      implementation 'io.reactivex:rxjava:1.1.6'
      implementation 'io.reactivex:rxandroid:1.2.1'
      implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    }
    In the past, Retrofit relied on the Gson library to serialize and deserialize JSON data. Retrofit 2 now supports many different parsers for processing network response data, including Moshi, a library build by Square for efficient JSON parsing. However, there are a few limitations, so if you are not sure which one to choose, use the Gson converter for now.
    ConverterLibrary
    Gsoncom.squareup.retrofit2:converter-gson:2.4.0
    Jacksoncom.squareup.retrofit2:converter-jackson:2.4.0
    Moshicom.squareup.retrofit2:converter-moshi:2.4.0
    Protobufcom.squareup.retrofit2:converter-protobuf:2.4.0
    Wirecom.squareup.retrofit2:converter-wire:2.4.0
    Simple XMLcom.squareup.retrofit2:converter-simplexml:2.4.0

    Create Java Classes for Resources

    There are two approaches discussed in this guide. The first way is the manual approach, which requires you to learn how to use the Gson library. The second approach is you can also auto-generate the Java classes you need by capturing the JSON output and using jsonschema2pojo. We encourage you to follow the manual way to best understand how the auto-generated code approach works.

    Manual approach - Creating Java classes by hand

    See this guide about leveraging the Gson library for more information about how to create your own Java classes for use with Retrofit. The guide shows how to use Gson to ingest data from the Rotten Tomatoes API, but it can be used in the same way for any RESTful web service.

    Automated approach - Auto-generating the Java classes

    Assuming you have the JSON response already, go to jsonschema2pojo. Make sure to select JSON as the Source Type:
    Set the Annotation style to Gson.
    Next, paste the JSON output into the textbox:
    POJO Generator
    Click the Preview button. You should see the top section look sort of like the following:
    Paste the generated class into your project under a models sub-package. Rename the class name Example to reflect your model name. For this example, we will call this file and class the User model.
    Note: Android does not come normally with many of the javax.annotation library by default. If you wish to keep the @Generated annotation, you will need to add this dependency. See this Stack Overflow discussion for more context. Otherwise, you can delete that annotation and use the rest of the generated code.
    dependencies {
      provided 'org.glassfish:javax.annotation:10.0-b28'
    }

    Creating the Retrofit instance

    To send out network requests to an API, we need to use the Retrofit builder class and specify the base URL for the service.
    // Trailing slash is needed
    
    public static final String BASE_URL = "http://api.myservice.com/";
    Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build();
    Note also that we need to specify a factory for deserializing the response using the Gson library. The order in which the converters are added will be the sequence in which they are attempted to be processed as discussed in this video talk. If we wish to pass in a custom Gson parser instance, it can be specified too:
    Gson gson = new GsonBuilder()
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
            .create();
    
    Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build();

    Define the Endpoints

    With Retrofit 2, endpoints are defined inside of an interface using special retrofit annotations to encode details about the parameters and request method. In addition, the return value is always a parameterized Call<T> object such as Call<User>. If you do not need any type-specific response, you can specify return value as simply Call<ResponseBody>.
    For instance, the interface defines each endpoint in the following way:
    public interface MyApiEndpointInterface {
        // Request method and URL specified in the annotation
    
    
        @GET("users/{username}")
        Call<User> getUser(@Path("username") String username);
    
        @GET("group/{id}/users")
        Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);
    
        @POST("users/new")
        Call<User> createUser(@Body User user);
    }
    Notice that each endpoint specifies an annotation of the HTTP method (GET, POST, etc.) and method that will be used to dispatch the network call. Note that the parameters of this method can also have special annotations:
    AnnotationDescription
    @Pathvariable substitution for the API endpoint (i.e. username will be swapped for {username} in the URL endpoint).
    @Queryspecifies the query key name with the value of the annotated parameter.
    @Bodypayload for the POST call (serialized from a Java object to a JSON string)
    @Headerspecifies the header with the value of the annotated parameter

    Changing the base URL

    Normally, the base URL is defined when you instantiated an Retrofit instance. Retrofit 2 allows you to override the base URL specified by changing it in the annotation (i.e. if you need to keep one specific endpoint using an older API endpoint)
    @POST("https://api.github.com/api/v3")
    There are also others that allow you to modify the base URL using relative paths (and not the fully qualified URL) as discussed in this blog article.

    Adding headers

    Notice that there is a @Headers and @Header annotation. The Headers can be used to provide pre-defined ones:
    @Headers({"Cache-Control: max-age=640000", "User-Agent: My-App-Name"})
    @GET("/some/endpoint")
    We can also add headers as a parameter to the endpoint:
    @Multipart
    @POST("/some/endpoint")
    Call<SomeResponse> someEndpoint(@Header("Cache-Control") int maxAge)

    Form data

    If we wish to submit form-encoded data, we can use the FormUrlEncoded annotation. The @Field annotation will denote what payload will be submitted as form data.
    @FormUrlEncoded
    @POST("/some/endpoint")
    Observable<SomeResponse> someEndpoint(@Field("code") String code);

    Multipart forms

    If we need to upload images or files, we need to send by using Multipart forms. We will to mark the endpoint with @Multipart, and label at least one parameter with @Part.
    @Multipart
    @POST("some/endpoint")
    Call<Response> uploadImage(@Part("description") String description, @Part("image") RequestBody image)
    Assuming we have a reference to the file, we can create a RequestBody object:
    MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
    file = new File("/storage/emulated/0/Pictures/MyApp/test.png");
    RequestBody requestBody = RequestBody.create(MEDIA_TYPE_PNG, file);
    
    Call<Response> call = apiService.uploadImage("test", requestBody);
    If you need to specify a unique filename for your multipart upload, there is currently an issue in Retrofit 2 tracked in this ticket. Alternatively, you can create a multi-part RequestBody according to this OkHttp recipe guide and pass it along as one of the @Part annotated parameters:
    RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("title", "Square Logo")
            .addFormDataPart("image", "logo-square.png",
                RequestBody.create(MEDIA_TYPE_PNG, new File("website/static/logo-square.png")))
            .build();

    Form URL encoding

    If we wish to POST form-encoded name/value pairs, we can use the @FormUrlEncoded and @FieldMap annotations:
    @FormUrlEncoded
    @POST("some/endpoint")
    Call<SomeResponse> someEndpoint(@FieldMap Map<String, String> names);

    POSTing JSON data

    Retrofit 2 will use the converter library chosen to handle the deserialization of data from a Java object. If you annotate the parameter with a @Body parameter, this work will be done automatically. If you are using the Gson library for instance, any field belonging to the class will be serialized for you. You can change this name using the @SerializedName decorator:
    public class User {
    
      @SerializedName("id")
      int mId;
    
      @SerializedName("name")
      String mName;
    
      public User(int id, String name ) {
        this.mId = id;
        this.mName = name;
      }
    }
    Our endpoint would look like the following:
    @POST("/users/new")
    Call<User> createUser(@Body User user);
    We could invoke this API call as follows:
    User user = new User(123, "John Doe");
    Call<User> call = apiService.createuser(user);
    call.enqueue(new Callback<User>() {
      @Override
      public void onResponse(Call<User> call, Response<User> response) {
    
      }
    
      @Override
      public void onFailure(Call<User> call, Throwable t) {
    
      }
    The resulting network call would POST this data:
    {"name":"John Doe","id":123}

    Upgrading from Retrofit 1

    If you are trying to upgrade from Retrofit 1, you may remember that the last parameter had to be a Callback type if you wanted to define the API call to run asynchronously instead of synchronously:
    public interface MyApiEndpointInterface {
        // Request method and URL specified in the annotation
    
        // Callback for the parsed response is the last parameter
    
    
        @GET("users/{username}")
        void getUser(@Path("username") String username, Callback<User> cb);
    
        @GET("group/{id}/users")
        void groupList(@Path("id") int groupId, @Query("sort") String sort, Callback<List<User>> cb);
    
        @POST("users/new")
        void createUser(@Body User user, Callback<User> cb);
    }
    Retrofit 1 relied on this Callback type as a last parameter to determine whether the API call would be dispatched asynchronously instead of synchronously. To avoid having two different calling patterns, this interface was consolidated in Retrofit 2. You now simply define the return value with a parameterized Call<T>, as shown in the previous section.

    Accessing the API

    We can bring this all together by constructing a service leveraging the MyApiEndpointInterface interface with the defined endpoints:
    MyApiEndpointInterface apiService =
        retrofit.create(MyApiEndpointInterface.class);
    If we want to consume the API asynchronously, we call the service as follows:
    String username = "sarahjean";
    Call<User> call = apiService.getUser(username);
    call.enqueue(new Callback<User>() {
        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            int statusCode = response.code();
            User user = response.body();  
        }
    
        @Override
        public void onFailure(Call<User> call, Throwable t) {
            // Log error here since request failed
    
        }
    });
    Shown above, Retrofit will download and parse the API data on a background thread, and then deliver the results back to the UI thread via the onResponse or onFailure method.
    Note also that OkHttp, which dispatches the callback on the worker thread, callbacks in Retrofit are dispatched on the main thread. Because UI updates can only be done on the main thread, the approach used by Retrofit can make it easier to make changes to your views.
    If you are using Retrofit in a Background Service instead of an Activity or Fragment, you can run the network call synchronously within the same thread by using the execute() method.
    try {
      Response<User> response = call.execute();
    } catch (IOException e ){
       // handle error
    
    }

    RxJava

    Retrofit 2 also supports RxJava extensions. You will need to create an RxJava Adapter. By default, all network calls are synchronous:
    RxJavaCallAdapterFactory rxAdapter = RxJava2CallAdapterFactory.create();
    If you wish to default network calls to be asynchronous, you need to use createWithScheduler().
    RxJavaCallAdapterFactory rxAdapter = RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io());
    You can then instantiate the Retrofit instance:
    Retrofit retrofit = new Retrofit.Builder()
                                   .baseUrl("https://api.github.com")
                                   .addConverterFactory(GsonConverterFactory.create())
                                   .addCallAdapterFactory(rxAdapter)
                                   .build();
    Instead of creating Call objects, we will use Observable types.
    public interface MyApiEndpointInterface {
        // Request method and URL specified in the annotation
    
        // Callback for the parsed response is the last parameter
    
    
        @GET("/users/{username}")
        Observable<User> getUser(@Path("username") String username);
    
        @GET("/group/{id}/users")
        Observable<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);
    
        @POST("/users/new")
        Observable<User> createUser(@Body User user);
    }
    Consistent with the RxJava framework, we need to create a subscriber to handle the response. The methods onCompleted()onError(), and onNext() need to be added. Using the Android RxJava library, we can also designate that we will handle this event on the UI main thread. Note: If you intend to override the default network call behavior, you can specify subscribeOn(). Otherwise, it can omitted. Note: As the RxJava rewrote their API, the term "Subscription" used here shall be replaced with "Disposable". As the word "Subscription" had conflict intentions.
    String username = "sarahjean";
    Observable<User> call = apiService.getUser(username);
    Disposable disposable = call
    .subscribeOn(Schedulers.io()) // optional if you do not wish to override the default behavior
    
    .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new Disposable<User>() {
      @Override
      public void onCompleted() {
    
      }
    
      @Override
      public void onError(Throwable e) {
        // cast to retrofit.HttpException to get the response code
    
        if (e instanceof HttpException) {
           HttpException response = (HttpException)e;
           int code = response.code();
        }
      }
    
      @Override
      public void onNext(User user) {
      }
    });
    Note that if you are running any API calls in an activity or fragment, you will need to unsubscribe on the onDestroy() method. The reasons are explained in this Wiki article:
    // MyActivity
    
    private Disposable disposable;
    
    protected void onCreate(Bundle savedInstanceState) {
        this.disposable = observable.subscribe(this);
    }
    
    ...
    
    protected void onDestroy() {
        this.disposable.dispose();
        super.onDestroy();
    }
    Note also that subscribing an observer to the observable is what triggers the network request. For more information about how to attach multiple observers before dispatching the network requests, see this section.

    Retrofit and Authentication

    Using Authentication Headers

    Headers can be added to a request using an Interceptor. To send requests to an authenticated API, add headers to your requests using an interceptor as outlined below:
    // Define the interceptor, add authentication headers
    
    Interceptor interceptor = new Interceptor() {
      @Override
      public okhttp3.Response intercept(Chain chain) throws IOException {
        Request newRequest = chain.request().newBuilder().addHeader("User-Agent", "Retrofit-Sample-App").build();
        return chain.proceed(newRequest);
      }
    };
    
    // Add the interceptor to OkHttpClient
    
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.interceptors().add(interceptor);
    OkHttpClient client = builder.build();
    
    // Set the custom client when building adapter
    
    Retrofit retrofit = new Retrofit.Builder()
      .baseUrl("https://api.github.com")
      .addConverterFactory(GsonConverterFactory.create())
      .client(client)
      .build();
    Notice that in Retrofit 2 the interceptor has to be added to a custom OkHttpClient. In Retrofit 1, it could be set directly by the builder class.

    Using OAuth

    In order to authenticate with OAuth, we need to sign each network request sent out with a special header that embeds the access token for the user that is obtained during the OAuth process. The actual OAuth process needs to be completed with a third-party library such as signpost and then the access token needs to be added to the header using a request interceptor. Relevant links for Retrofit and authentication below:
    Resources for using signpost to authenticate with an OAuth API:
    Several other Android OAuth libraries can be explored instead of signpost:

    Issues

    There is a known issue currently with Retrofit 2 passing Lint tests tracked in this ticket. In particular, you may see package reference in library; not included in Android: java.nio.file. Referenced from okio.Okio. or Invalid package reference in library; not included in Android: java.lang.invoke. Referenced from retrofit.Platform.Java8..
    To bypass this issue, create a gradle/lint.xml in your root project:
    <?xml version="1.0" encoding="UTF-8"?>
    <lint>
        <issue id="InvalidPackage">
            <ignore regexp=".*okio.*" />
            <ignore regexp=".*retrofit.*" />
        </issue>
    </lint>
    Add this line to your app/build.gradle file:
    lintOptions {
        lintConfig rootProject.file('gradle/lint.xml')
    }
    The lint errors should be suppressed and not trigger any additional errors for now.

    Troubleshooting

    Retrofit and OkHttp can be hard to troubleshoot when trying to step through the various layers of abstraction in the libraries. You can add the HttpLogInterceptor that can be added when using the OkHttp3 library, which will print HTTP requests/responses through LogCat. You can also leverage Facebook's Stetho project to use Chrome to inspect all network traffic.

    HttpLogInterceptor

    To use HttpLogInterceptor, add this dependency to your Gradle configuration:
    implementation 'com.squareup.okhttp3:logging-interceptor:3.3.0'
    You will need to add a network interceptor for HttpLogInterceptor. See this doc for the different options that can be used.
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    
    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
    
    // Can be Level.BASIC, Level.HEADERS, or Level.BODY
    
    // See http://square.github.io/okhttp/3.x/logging-interceptor/ to see the options.
    
    httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    builder.networkInterceptors().add(httpLoggingInterceptor);
    builder.build();
    You then need to pass this custom OkHttpClient into the Retrofit builder:
    Retrofit retrofit = new Retrofit.Builder()
                     .client(okHttpClient)

    Stetho

    Facebook's Stetho project enables you to use Chrome debugging tools to troubleshoot network traffic, database files, and view layouts. See this guide for more details.

    References

    **

    **

    **

    Comments

    1. Mandarin Drama Website/Api >>>>> Download Now

      >>>>> Download Full

      Mandarin Drama Website/Api >>>>> Download LINK

      >>>>> Download Now

      Mandarin Drama Website/Api >>>>> Download Full

      >>>>> Download LINK Kw

      ReplyDelete

    Post a Comment

    Popular posts from this blog

    Udacity, ud1110, Intro to Python, Lesson2 Data Strucures,

    Jay Chou, Ge Qian, Chinese, Character, Simplified, Pinyin, English, Lyrics,

    Comparing "hui," "neng," "keyi"