Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source of tweets retrieved by stream API is null for about two days now. #52

Open
lamrongol opened this issue Dec 9, 2022 · 3 comments

Comments

@lamrongol
Copy link

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();
}
@lamrongol
Copy link
Author

I confirmed now this problem doesn't occur.

@lamrongol
Copy link
Author

This problem occurs again today(December 21, 2022).

@salfagan81
Copy link

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();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants