Retrofit call to server 2.0.0Beta2, nothing happening - callback never invoked

我们两清 提交于 2019-12-13 06:17:11

问题


I make the call like such:

ApiInterface.getKidMixClient(getActivity()).getAccountDetails().enqueue(LoginFragment.this);

Here is my interface definition:

@GET(Endpoints.GET_MY_ACCOUNT_DETAILS+"/")
Call<Account> getAccountDetails();

But my callback onResponse is never being invoked?

Is there something wrong with this set up?

public class ApiInterface {
private static ApiService apiInterface;

public static ApiService getKidMixClient(final Context context) {
    if (apiInterface == null) {

        OkHttpClient client = new OkHttpClient();
        client.interceptors().add(new Interceptor() {
            @Override
            public Response intercept(Chain chain) throws IOException {
                Request request = chain.request();
                String authToken = SharedPrefsManager.get(context).getAccessToken();
                request.newBuilder()
                        .addHeader("Authorization", "Bearer " + authToken)
                        .addHeader("Content-Type", "application/json")
                        .build();
                chain.proceed(request);
                return intercept(chain);
            }
        });

        Gson gson = new GsonBuilder()
                .setExclusionStrategies(new ExclusionStrategy() {
                    @Override
                    public boolean shouldSkipField(FieldAttributes f) {
                        return f.getDeclaringClass().equals(RealmObject.class);
                    }

                    @Override
                    public boolean shouldSkipClass(Class<?> clazz) {
                        return false;
                    }
                })
                .create();

        Retrofit restAdapter = new Retrofit.Builder()
                .baseUrl(Endpoints.ENDPOINT_BASE_URL+Endpoints.ENDPOINT_VERSION)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(client)
       /*         .setRequestInterceptor(new RequestInterceptor() {
                    @Override
                    public void intercept(RequestFacade request) {
                        String authToken = SharedPrefsManager.get(context).getAccessToken();
                        request.addHeader("Authorization", "Bearer " + authToken);
                        request.addHeader("Content-Type", "application/json");
                    }
                })*/
                .build();

        apiInterface = restAdapter.create(ApiService.class);
    }

    return apiInterface;
}

}

this is the callback that should be getting called, but never is:

 @Override
public void onResponse(Response<Account> response, Retrofit retrofit) {
    Log.v("Call Success", "Call was a sucess to server login!");
    Account account = response.body();
    if(account != null && account.getUser() != null){
        if(callbacks != null){
            Log.d(TAG, "start");
            callbacks.showDashboard(account.getUser());
            Log.d(TAG, "finish");
        }
    }
}

It is in the LoginFragment class, of which the initial call is being made via enqueue.

来源:https://stackoverflow.com/questions/33026897/retrofit-call-to-server-2-0-0beta2-nothing-happening-callback-never-invoked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!