I am unable to populate a JavaFX Tableview with Twitter Search API response using Gluon Connect. I am trying to populate a JavaFX table with Date/Time, User and their Tweet.
I have setup a connection to the NewsAPI and successfully retrieved the JSON and was able to populate my Table.
I followed exactly the same approach with connecting to the Twitter Search API. I have tested the connection on Postman and it works.
I can't figure out whether I've created the RestClient incorrectly or if I'm not handling the response correctly or the issue is related to something else.
I've done GluonObservableList .isInitialised() and get False. Which indicates the GluonObservableList has not initialised.
This is my code for the NEWS API which works perfectly.
// create a RestClient to the specific URL
RestClient NewsRestClient = RestClient.create()
.method("GET")
.host("https://newsapi.org")
.path("//v2/everything?q=GBP_USD&from=2019-08-21&to=2019-08-21&sortBy=popularity&apiKey=9a7a9daab76f440fb796350c83db0694");
InputStreamIterableInputConverter<Article> converter = new ArticlesIterableInputConverter<>(Article.class);
GluonObservableList<Article> articles = DataProvider.retrieveList(NewsRestClient.createListDataReader(converter));
articles.initializedProperty().addListener((obv,ov,nv)-> {
newsTbl.setItems(articles);
newsDateCol.setCellValueFactory(new PropertyValueFactory<>("publishedAt"));
newsPublisherCol.setCellValueFactory((new PropertyValueFactory<>("name")));
newsTitleCol.setCellValueFactory(new PropertyValueFactory<>("title"));
newsURLCol.setCellValueFactory(new PropertyValueFactory<>("url"));
});
This is the code for my Twitter API which doesn't work.
RestClient TwitterRestClient = RestClient.create()
.method("GET")
.host("https://api.twitter.com")
.path("/1.1/search/tweets.json?q=USD_GBP")
.consumerKey("XXXXXXXXXX")
.consumerSecret("XXXXXXXX");
InputStreamIterableInputConverter<Tweet> converter2 = new TwitterIterableInputConverter<>(Tweet.class);
GluonObservableList<Tweet> tweets = DataProvider.retrieveList(TwitterRestClient.createListDataReader(converter2));
System.out.println(tweets.initializedProperty());
System.out.println(tweets.isInitialized());
tweets.initializedProperty().addListener((obv,ov,nv)-> {
twitterTbl.setItems(tweets);
twTime.setCellValueFactory(new PropertyValueFactory<>("created_at"));
twUserID.setCellValueFactory((new PropertyValueFactory<>("name")));
twTweet.setCellValueFactory(new PropertyValueFactory<>("text"));
});
This is my POJO
public class Tweet {
private String text;
private String created_at;
private User user;
public Tweet() {
}
public String getName() {
return user.getName();
}
public Tweet(String text, String created_at, User user) {
this.text = text;
this.created_at = created_at;
this.user = user;
}
public String getText() {
return text;
}
public String getCreated_at() {
return created_at;
}
@Override
public String toString() {
return "Tweet{"+",text='"+text+'\''+", created_at='"+created_at+'\'' +'}';
}
public static class User {
String name;
public String getName() {
return this.name;
}
}
}
To troubleshoot I ran
System.out.println(tweets.initializedProperty());
System.out.println(tweets.isInitialized());
This is the output i get ...
BooleanProperty [bean: [], name: initialized, value: false]
false
System.out.println(tweets.exceptionProperty());
ObjectProperty [bean: [], name: exception, value: null]