Freso:如何设置 OK Http 客户端?

Freso: How can I set the OK Http client?

所以我请求的一些图像需要添加身份验证header

我正在使用 Retrofit 2.0,它有一个带拦截器的 OkHttp 客户端,用于将用户令牌添加到每个请求的 header

 okHttpClient.interceptors().add(new Interceptor() {

            @Override
            public Response intercept(Chain chain) throws IOException {
                Request originalRequest = chain.request(); //Current Request
                Request requestWithToken = null; //The request with the access token which we will use if we have one instead of the original
                requestWithToken = originalRequest.newBuilder().addHeader(Constants.UrlParamConstants.HEADER_AUTHORIZATION,String.format(Constants.UrlParamConstants.HEADER_AUTHORIZATION_VALUE, MyApplication.getInstance().getUser().getApiToken())).build();
                Response response = chain.proceed((requestWithToken != null ? requestWithToken : originalRequest)); //proceed with the request and get the response
                return response;
            }
        });

我想知道如何为 Fresco 库设置相同的 okHttp 客户端实例。

我知道您需要添加此依赖项才能将 OkHttp 与 Fresco 一起使用,但是如何设置客户端?

  compile "com.facebook.fresco:imagepipeline-okhttp:0.8.0+"

归根结底,我只需要为图像请求设置身份验证header

感谢阅读

http://frescolib.org/docs/using-other-network-layers.html

Context context;
OkHttpClient okHttpClient; // build on your own
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
    .newBuilder(context, okHttpClient)
    . // other setters
    . // setNetworkFetcher is already called for you
    .build();
Fresco.initialize(context, config);