I can not figure out how to do it.

Call<RequestBody> call = mService.postToken(post); call.enqueue(new Callback<RequestBody>() { @Override public void onResponse(@NonNull Call<RequestBody> call, @NonNull Response<RequestBody> response) { if (response.isSuccessful() && response.body() != null) { // вот здесь что-то нужно прописать, но я не знаю } } @Override public void onFailure(@NonNull Call<RequestBody> call, @NonNull Throwable t) { } }); 

This is pojo

 public class RequestBody implements Serializable { @SerializedName("id_token") @Expose private String idToken; public RequestBody(String idToken) { super(); this.idToken = idToken; } public String getIdToken() { return idToken; } public void setIdToken(String idToken) { this.idToken = idToken; } 

}

And this is the interface:

 @FormUrlEncoded @POST(" ") Call<List<RequestBody>> postParams(@Field("id_token") String id_token); 

How to write this id_token into a String variable?

  • you can use the prefs or make a class for this - Andrew Goroshko

1 answer 1

It is not entirely clear that you do not understand. It seems everything is correct. Your class is created in the successful branch.

 RequestBody requestBody = new RequestBody(response.body()) String IdToken = requestBody.idToken 

And use it as you wish.

If the question was how to use in the whole project, then probably the best solution would be to save in the SharedPreference, and in the right place pull out and use. As for the class, I don’t understand why you are sending token_id, and then you receive it (maybe something else, all of a sudden you have such logic)