public static OAuthServerIntf getYandex() {
Retrofit raCustom = new Retrofit.Builder()
.client(new OkHttpClient())
.baseUrl("https://cloud-api.yandex.net")
.addConverterFactory(GsonConverterFactory.create())
.build();
OAuthServerIntf webServer = raCustom.create(OAuthServerIntf.class);
return webServer;
}
The call refreshTokenFormCall failed
java.io.IOException: Use JsonReader.setLenient(true) to accept malformed JSON at path $
at com.squareup.moshi.BufferedSourceJsonReader.syntaxError(BufferedSourceJsonReader.java:1094)
at com.squareup.moshi.BufferedSourceJsonReader.checkLenient(BufferedSourceJsonReader.java:990)
at com.squareup.moshi.BufferedSourceJsonReader.doPeek(BufferedSourceJsonReader.java:374)
at com.squareup.moshi.BufferedSourceJsonReader.peek(BufferedSourceJsonReader.java:202)
at com.squareup.moshi.JsonAdapter$1.fromJson(JsonAdapter.java:65)
at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:33)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:32)
at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:23)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
public class Interceptors implements Interceptor {
private static final String TAG = "OAuthInterceptor";
private String accessToken,accessTokenType;
@Override
public Response intercept(Chain chain) throws IOException {
OAuthToken oauthToken=OAuthToken.Factory.create();
accessToken=oauthToken.getAccessToken();
accessTokenType=oauthToken.getTokenType();
Request.Builder builder = chain.request().newBuilder();
if (!TextUtils.isEmpty(accessToken)&&!TextUtils.isEmpty(accessTokenType)) {
builder.header("Authorization",accessTokenType+" " + accessToken);
}else{
Intent i = new Intent(MyApplication.instance, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
MyApplication.instance.startActivity(i);
}
return chain.proceed(builder.build());
}
}
@NonNull
public static OkHttpClient getOAuthOkHttpClient(Context ctx) {
Interceptor oAuthInterceptor=new Interceptors();
HttpLoggingInterceptor httpLogInterceptor=new HttpLoggingInterceptor();
httpLogInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder()
.addInterceptor(oAuthInterceptor)
.addInterceptor(httpLogInterceptor)
.build();
}