I am using retrofit for the first time.I want to get the authentication returned from the Api but onResponse is not called. Here is my code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://abc.def.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface service = retrofit.create(ApiInterface.class);
String setAPI_KEY = "123456";
String settoken = "7891011";
retrofit2.Call<TokenResponse> tokenResponseCall = service.getToken(setAPI_KEY, settoken);
tokenResponseCall.enqueue(new Callback<TokenResponse>() {
@Override
public void onResponse(retrofit2.Call<TokenResponse> call, retrofit2.Response<TokenResponse> response) {
int a = response.code();
TokenResponse tokenResponse = new TokenResponse();
}
@Override
public void onFailure(retrofit2.Call<TokenResponse> call, Throwable t) {
System.out.print("Fail");
}
});
In the Interface I am setting it like this:
public interface ApiInterface {
@GET("/qwe/asd/zxc")
Call<TokenResponse> getToken(@Query("key") String API_KEY,@Query("acesstoken") String token);
}
Any idea whats wrong in it? The complete URL is like this
https://abc.def.com/qwe/asd/zxc?key=Key&acesstoken=Token
Here is my TokenResponse Class:
public class TokenResponse {
@SerializedName("authorization_key")
private String authorization_key;
public String getAuthorization_key() {
return authorization_key;
}
}
The Exception I am getting is : com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $