twitter-api-java-sdk
twitter-api-java-sdk copied to clipboard
`source` of tweets retrieved by stream API is null for about two days now.
source
of tweets retrieved by stream API is null for about two days now.
Expected behavior
tweet.getSource()
returns the source.
Actual behavior
tweet.getSource()
returns null
Steps to reproduce the behavior
Normally using stream API.
TwitterApi apiInstance = new TwitterApi(
new TwitterCredentialsBearer(
"XXXX"//dummy
));
// Set the params values
Set<String> tweetFields = new HashSet<>(Arrays.asList("id", "author_id", "created_at", "lang", "source", "text", "entities", "public_metrics")); // Set<String> | A comma separated list of Tweet fields to display.
Set<String> expansions = new HashSet<>(Arrays.asList()); // Set<String> | A comma separated list of fields to expand.
Set<String> mediaFields = new HashSet<>(Arrays.asList()); // Set<String> | A comma separated list of Media fields to display.
Set<String> pollFields = new HashSet<>(Arrays.asList()); // Set<String> | A comma separated list of Poll fields to display.
Set<String> userFields = new HashSet<>(Arrays.asList("created_at", "description", "public_metrics", "verified")); // Set<String> | A comma separated list of User fields to display.
Set<String> placeFields = new HashSet<>(Arrays.asList("country_code")); // Set<String> | A comma separated list of Place fields to display.
try {
InputStream result = apiInstance.tweets().sampleStream()
.tweetFields(tweetFields)
.expansions(expansions)
.mediaFields(mediaFields)
.pollFields(pollFields)
.userFields(userFields)
.placeFields(placeFields)
.execute();
try {
Type localVarReturnType = new TypeToken<StreamingTweetResponse>() {
}.getType();
BufferedReader reader = new BufferedReader(new InputStreamReader(result, "UTF-8"));
String line = reader.readLine();
while (line != null) {
if (line.isEmpty()) {
//System.out.println("==> Empty line");
line = reader.readLine();
continue;
}
//System.out.println(response != null ? response.toString() : "Null object");
try {
StreamingTweetResponse response = JSON.getGson().fromJson(line, localVarReturnType);
if (response != null) {
Tweet tweet = response.getData();
//------------------------------------
//------------------------------------
//------------------------------------
//Place which problem happens.
if (tweet != null) System.out.println(tweet.getSource());//null
//------------------------------------
//------------------------------------
//------------------------------------
}
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage() + ": " + line);
}
line = reader.readLine();
}
} catch (StreamResetException e) {
e.printStackTrace();
String[] tmp = new String[0];
main(tmp);
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e) {
System.err.println("Exception when calling TweetsApi#sampleStream");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}