Я пытаюсь использовать API с токеном на предъявителя, но всегда получаю ложный ответ, а тело ответа равно нулю.
public interface FreelancerService {
@Headers("Accept: application/json")
@GET("api/freelancers/1")
Call<Model> getData( @Header("Authorization") String authorization);}`
Создание экземпляра Retrofit
private static final String BASE_URL = "https://match.maffia.ca/";
public static Retrofit getRetrofitInstance(){
if (retrofit == null){
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(logging)
.build();
retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
}
return retrofit;
}
Ивызов ...
FreelancerService service = RetrofitInstance.getRetrofitInstance().create(FreelancerService.class);
Call<Model> data = service.getData("Bearer " + R.string.token);
data.enqueue(new Callback<Model>() {
@Override
public void onResponse(Call<Model> call, Response<Model> response) {
Log.d(TAG, "onResponse: " + response.isSuccessful());
}
@Override
public void onFailure(Call<Model> call, Throwable t) {
Log.d(TAG, "onFailure: " + t.getMessage());
}
});
Класс модели
public class Model {
@SerializedName("data") @Expose
private Data data;
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}}
Класс данных
public class Data {
@SerializedName("freelancer")@Expose
private Freelancer freelancer;
public Freelancer getFreelancer() {
return freelancer;
}
public void setFreelancer(Freelancer freelancer) {
this.freelancer = freelancer;
}}
Точно так же у меня есть еще много классов.
JSON, который я пытаюсь получить.
{
"data": {
"freelancer": {
"id": 1,
"job_title": "Copy & comedy writer",
"vat": null,
"resume": null,
"linkedin": null,
"has_email_notification": null,
"has_whatsapp_notification": null,
"is_snoozing": null,
"snoozing_until": null,
"snoozing_from": null,
"is_member": 0,
"member_until": null,
"other_languages": null,
"location_id": 2,
"project_type_id": 3,
"minimum_day_rate_id": 1,
"experience_id": 5,
"user_id": 3,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51",
"deleted_at": null,
"competence_values": [
"Schrijven",
"rijmen",
"dichten",
"cartoons maken en meer."
],
"language_ids": [
1,
3
],
"service_ids": [
13,
24,
33,
34,
16
],
"availability_ids": [
4
],
"user": {
"id": 3,
"first_name": "Johan Sebastiaan",
"last_name": "Stuer",
"email": "johan.sebastiaan.stuer@gmail.com",
"mobile": "0472809137",
"has_accepted_general_conditions": 1,
"has_accepted_maffia_conditions": 0,
"newsletter_subscriber": 1,
"type": "freelancer",
"avatar": "public/avatars/default.png",
"gender_id": 1,
"email_verified_at": null,
"api_token": null,
"created_at": "2019-09-02 10:54:50",
"updated_at": "2019-09-02 10:54:50",
"deleted_at": null
},
"languages": [
{
"id": 1,
"name": "Dutch",
"created_at": "2019-09-02 10:51:44",
"updated_at": null,
"deleted_at": null,
"languages": {
"freelancer_id": 1,
"language_id": 1,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 3,
"name": "English",
"created_at": "2019-09-02 10:51:44",
"updated_at": null,
"deleted_at": null,
"languages": {
"freelancer_id": 1,
"language_id": 3,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
}
],
"services": [
{
"id": 13,
"name": "Copy writing",
"created_at": "2019-09-02 10:51:43",
"updated_at": null,
"deleted_at": null,
"services": {
"freelancer_id": 1,
"service_id": 13,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 24,
"name": "Illustration",
"created_at": "2019-09-02 10:51:43",
"updated_at": null,
"deleted_at": null,
"services": {
"freelancer_id": 1,
"service_id": 24,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 33,
"name": "Social media",
"created_at": "2019-09-02 10:51:44",
"updated_at": null,
"deleted_at": null,
"services": {
"freelancer_id": 1,
"service_id": 33,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 34,
"name": "Translation",
"created_at": "2019-09-02 10:51:44",
"updated_at": null,
"deleted_at": null,
"services": {
"freelancer_id": 1,
"service_id": 34,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 16,
"name": "Desktop publishing",
"created_at": "2019-09-02 10:51:43",
"updated_at": null,
"deleted_at": null,
"services": {
"freelancer_id": 1,
"service_id": 16,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
}
],
"competences": [
{
"id": 1,
"name": "Schrijven",
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51",
"deleted_at": null,
"competences": {
"freelancer_id": 1,
"competence_id": 1,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 2,
"name": "rijmen",
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51",
"deleted_at": null,
"competences": {
"freelancer_id": 1,
"competence_id": 2,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 3,
"name": "dichten",
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51",
"deleted_at": null,
"competences": {
"freelancer_id": 1,
"competence_id": 3,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
},
{
"id": 4,
"name": "cartoons maken en meer.",
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51",
"deleted_at": null,
"competences": {
"freelancer_id": 1,
"competence_id": 4,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
}
],
"availabilities": [
{
"id": 4,
"option": "On offer",
"created_at": "2019-09-02 10:51:44",
"updated_at": null,
"deleted_at": null,
"freelancer_availabilities": {
"freelancer_id": 1,
"availability_id": 4,
"created_at": "2019-09-02 10:54:51",
"updated_at": "2019-09-02 10:54:51"
}
}
]
}
}}
Я не могу понять, в чем проблема. Когда я нажимаю API в Postman с авторизацией как «Bearer Token», я получаю результат.