twitter4j - access tweet information from Streaming API

后端 未结 3 577
我在风中等你
我在风中等你 2021-02-01 11:01

My goal is to collect all tweets containing the words \"France\" and \"Germany\" and to also collect associated metadata (e.g., the geo coordinates attached to the tweet). I kno

相关标签:
3条回答
  • 2021-02-01 11:37

    After looking at this with fresh eyes I realised the solution (which was pretty obvious). Editing the following part of the code:

    public void onStatus(Status status) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }
    

    allows me to access other metadata. For example, if I want to access the tweet's date, I simply need to add the following:

    System.out.println(status.getCreatedAt());
    
    0 讨论(0)
  • 2021-02-01 11:39

    The Error 401 comes when the API is trying to access some information which is unable to fetch at present. So you need to check the permission which are allowed on twitter. Change it to READ, WRITE and ... for full API access. Or there might be problem as you might be using the proxy server. Hence mention the proxy details using the following commands.

     System.getProperties().put("http.proxyHost", "10.3.100.211");
            System.getProperties().put("http.proxyPort", "8080");
    
    0 讨论(0)
  • 2021-02-01 11:55

    To write tweets on file:

    FileWriter file = new FileWriter(....);
    
    public void onStatus(Status status) {
        System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText() + " -> "+ status.getCreatedAt());
        try {
            file.write(status.getUser().getScreenName() + " - " + status.getText() + " -> "+ status.getCreatedAt() +"\n");
            file.flush();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    0 讨论(0)
提交回复
热议问题