0

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]
  • You can use `tweets.exceptionProperty()` to find out about a possible exception in the process. Print it out and see what is failing. You should probably need to move `User` to an external class. – José Pereda Aug 25 '19 at 11:06
  • Hi Jose, ..Thanks again for replying. According to the output the Exception is null. – Mahen Padayachee Aug 25 '19 at 12:40
  • Did you move `User` to a class? Does the converter receive any data? – José Pereda Aug 25 '19 at 12:42
  • Man you reply fast ! Before i move the User to a separate class, can you tell me if i then need to make separate converters and GluonObservable Lists for each class ? The thing is, these JSON responses have Arrays of Lists, and that would mean each List would have to become a class. I followed this https://stackoverflow.com/questions/50620797/json-to-pojo-with-nested-values, to create my POJOS. – Mahen Padayachee Aug 25 '19 at 12:51
  • You can have nested POJOs with one single converter, typically based on the main array within the JSON. However, If data is spread over different arrays you may need a different approach using a GluonObservableObject instead of a GluonObservableList. The top POJO will contain lists for the arrays in the JSON. So it depends on each case. – José Pereda Aug 25 '19 at 12:57
  • Hi, I've moved the User to a separate class, still no luck. You asked if the converter receives any data. I cant find a way to verify this. I tried looking at the docs but i couldnt find anything. – Mahen Padayachee Aug 25 '19 at 14:14
  • You can try adding some printouts to the converter methods, and see if they get called, or if you get anything at `iterator()`? – José Pereda Aug 25 '19 at 17:56
  • Hi Jose' , i think I figured out what the problem is. I had the same problem trying to populate a table with Forex data, anything over 5 rows and the Table doesn't load the content, and given the amount of info in the Twitter JSON, would explain why im not seeing anything on the table. Im just going to have to do it the hard way now. Thanks for helping. – Mahen Padayachee Aug 25 '19 at 23:32

0 Answers0