помогите распарсить getUpdates в API telegram....
суть в том что ссылка парсится, а вот данные приходят NULL....
https://api.telegram.org/bot1080783949:AAEvVVE_fmi...
делаю через библиотеку Retrofit 2....
в MainActivity:
NetworkService.getInstance()
.getJSONApi()
.operation("result")
.enqueue(new Callback<Post>() {
@Override
public void onResponse(@NonNull Call<Post> call, @NonNull Response<Post> response) {
Post post = response.body();
Log.v("response1", post.getUpdateId() + " " + post.getId() + " " + post.getMessageId()+ " " +
post.getText());
}
@Override
public void onFailure(@NonNull Call<Post> call, @NonNull Throwable t) {
Toast.makeText(MainActivity.this, "Error occurred while getting request!",
Toast.LENGTH_SHORT).show();
//textView.append("Error occurred while getting request!");
t.printStackTrace();
}
});
код NetworkService:
public class NetworkService {
private static NetworkService mInstance;
private static final String BASE_URL = "https://api.telegram.org";
private Retrofit mRetrofit;
public static final String LOGIN_OPERATION = "login";
private NetworkService() {
mRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static NetworkService getInstance() {
if (mInstance == null) {
mInstance = new NetworkService();
NetworkService.getInstance()
.getJSONApi()
.operation("result")
.enqueue(new Callback<Post>() {
private Context context;
@Override
public void onResponse(@NonNull Call<Post> call, @NonNull Response<Post> response) {
Post post = response.body();
}
@Override
public void onFailure(@NonNull Call<Post> call, @NonNull Throwable t) {
Toast.makeText(context, "Error occurred while getting request!", Toast.LENGTH_SHORT).show();
t.printStackTrace();
}
});
}
return mInstance;
}
public JSONPlaceHolderApi getJSONApi() {
return mRetrofit.create(JSONPlaceHolderApi.class);
}
код JSONPlaceHolderApi :
public interface JSONPlaceHolderApi {
@POST("/bot1080783949:AAEvVVE_fmiHqBU9Oy_rd2RxTmxdbWQOdAc/getUpdates")
Call<Post> operation(@Body String request);
}
код Post:
public class Post {
@SerializedName("update_id")
@Expose
private double update_id;
@SerializedName("message_id")
@Expose
private int message_id;
@SerializedName("id")
@Expose
private double id;
@SerializedName("username")
@Expose
private String username;
@SerializedName("date")
@Expose
private double date;
@SerializedName("text")
@Expose
private String text;
public double getUpdateId() {
return update_id;
}
public void setUpdateId(double update_id) {
this.update_id = update_id;
}
public int getMessageId() {
return message_id;
}
public void setMessageId(int message_id) {
this.message_id = message_id;
}
public double getId() {
return id;
}
public void setId(double id) {
this.id = id;
}
public String getUserName() {
return username;
}
public void setUserName(String username) {
this.username = username;
}
public double getDate() {
return date;
}
public void setDate(double date) {
this.date = date;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}