retrofit

How to parse Retrofit JSON response

纵饮孤独 提交于 2020-01-22 17:08:10
问题 I have a typical Retrofit API request: RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(URL) .build(); ApiEndpointInterface api = restAdapter.create(ApiEndpointInterface.class); api.getToken('1', new Callback<DefaultResponse>() { @Override public void success(DefaultResponse json, Response response) { // } @Override public void failure(RetrofitError response) { // } }); And the returned JSON is: {"success":true,"data":{"token_id":"pPt9AKl0Cg","token_key":"8ax224sFrJZZkStAQuER"

Okhttp refresh expired token when multiple requests are sent to the server

試著忘記壹切 提交于 2020-01-22 04:30:45
问题 I have a ViewPager and three webservice calls are made when ViewPager is loaded simultaneously. When first one returns 401, Authenticator is called and I refresh the token inside Authenticator , but remaining 2 requests are already sent to the server with old refresh token and fails with 498 which is captured in Interceptor and app is logged out. This is not the ideal behaviour I would expect. I would like to keep the 2nd and 3rd request in the queue and when the token is refreshed, retry the

(Slim + Retrofit Android Studio App)Requests not working

≡放荡痞女 提交于 2020-01-22 02:21:11
问题 I’m developing an android app using Slim Framework and Retrofit Library to connect de API to the app, but I have a problem, when I’m working in my pc and I try the app using the Android Studio emulator everything works fine, but when I use my laptop with the same API and the same Android Studio project, it seems that the requests aren’t workin, I mean, when I press a button to login the app doesn’t do the request or the request doesn’t work and I dont know why. Anyone could know how to fix it

(Slim + Retrofit Android Studio App)Requests not working

守給你的承諾、 提交于 2020-01-22 02:21:08
问题 I’m developing an android app using Slim Framework and Retrofit Library to connect de API to the app, but I have a problem, when I’m working in my pc and I try the app using the Android Studio emulator everything works fine, but when I use my laptop with the same API and the same Android Studio project, it seems that the requests aren’t workin, I mean, when I press a button to login the app doesn’t do the request or the request doesn’t work and I dont know why. Anyone could know how to fix it

Retrofit returns LinkedTreeMap instead of JSON

故事扮演 提交于 2020-01-21 14:57:49
问题 I am using Retrofit 2.0 to read data from a web service which returns a json text, but in following code response is LinkedTreeMap and I can't convert it to json: My interface public interface GeoAPIInterface { String ENDPOINT = "http://www.geoplugin.net/"; @GET("json.gp") Call<Object> getIP(@Query("ip") String ip); } Now I read data from site : Retrofit retrofit = new Retrofit.Builder() .baseUrl(GeoAPIInterface.ENDPOINT) .addConverterFactory(GsonConverterFactory.create()) .build();

RxJava - Combining multiple/different web service calls

偶尔善良 提交于 2020-01-21 12:44:16
问题 I'm working with the Basecamp api to return and display to do lists. Here's a sample of what I'm doing at the moment: bcxClient .fetchToDoLists() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<BcxToDoList>>() { @Override public void call(List<BcxToDoList> bcxToDoLists) { for( final BcxToDoList toDoList : bcxToDoLists ) { bcxClient .fetchToDos( toDoList.bucket.id ) .subscribeOn( Schedulers.io() ) .observeOn( AndroidSchedulers.mainThread() )

RxJava - Combining multiple/different web service calls

别等时光非礼了梦想. 提交于 2020-01-21 12:42:17
问题 I'm working with the Basecamp api to return and display to do lists. Here's a sample of what I'm doing at the moment: bcxClient .fetchToDoLists() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<BcxToDoList>>() { @Override public void call(List<BcxToDoList> bcxToDoLists) { for( final BcxToDoList toDoList : bcxToDoLists ) { bcxClient .fetchToDos( toDoList.bucket.id ) .subscribeOn( Schedulers.io() ) .observeOn( AndroidSchedulers.mainThread() )

particular title(fetched from api) using searchview?

瘦欲@ 提交于 2020-01-18 10:48:26
问题 I want something like this---> Required so the thing is, what I exactly want is when user type particular topic name(if present in-app) in searchview it should able give suggestions and if found it should open that topic activity ( just like Facebook, Instagram,...etc searches )..and those title are coming from API(which I have successfully displayed in other activities)..like this--> [enter image description here..what will the logic for it??? need help... Thanks so I have just included

网络框架——Retrofit

巧了我就是萌 提交于 2020-01-18 09:45:16
Retrofit的注解分类 Retrofit的注解分为三大类,分别是:HTTP请求方法注解、标记类注解、参数类注解 GET请求 首先创建爱你请求地址和返回参数类型 public interface IpService { @GET("getIpInfo.php?ip=59.108.54.37") Call<IpModel> getIpMsg(); } 创建请求 private void getIp() { String url = "http://ip.taobao.com/service/"; Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .addConverterFactory(GsonConverterFactory.create())//增加返回值Json支持 .build(); IpService ipService = retrofit.create(IpService.class); Call<IpModel> call = ipService.getIpMsg(); call.enqueue(new Callback<IpModel>() { @Override public void onResponse(Call<IpModel> call, Response<IpModel> response

Retrofit分析-漂亮的解耦套路

≯℡__Kan透↙ 提交于 2020-01-18 09:21:12
没耐心自己分析源码的同学,还可以参考Stay录制的视频版 Retrofit分析-漂亮的解耦套路(视频版) 万万没想到Retrofit会这么火,在没看源码之前,我简单的认为是因为它跟OkHttp同出一源(Square),所以才会炒的那么热。又或者是因为它能支持RxJava,所以火上浇油,一发不可收拾。 后来看过Retrofit源码之后,我才理解为什么它倍受关注,是因为它集诸优点于一身,并且炒鸡解耦。你能预见的特殊需求,都能非常容易的扩展。 没有HTTP框架的日子 我们先来看一下没有HTTP框架以前,我们是如何做请求的。 首先build request参数 因为不能在主线程请求HTTP,所以你得有个Executer或者线程 enqueue后,通过线程去run你的请求 得到服务器数据后,callback回调给你的上层。 大概是以上4大步骤,在没有框架的年代,想要做一次请求,是万分痛苦的,你需要自己管理线程切换,需要自己解析读取数据,解析数据成对象,切换回主线程,回调给上层。 这段空白的时间持续了很久。从我10年工作起到12年,因为写烦了重复的代码,所以就得想办法,把那些变化的地方封装起来,也只是简单的封装。好在官方出了AsyncTask,虽然坑很多,但如果再自己维护一个队列,基本不会出现问题。更好的地方是数据格式从xml变成json了。gson解放了双手,再也不用解析dom了。