Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes Made:
Error Handling:
Added proper error handling to ensure the program doesn't crash unexpectedly.
Included checks for the bearerToken to ensure it is not null or empty.
Added max_results Parameter:
Added max_results to limit the number of results returned. Adjust it as per your requirements (e.g., 10, 50, or 100).
Improved Readability:
Added comments to clarify each section of the code.
Improved formatting for better readability.
Enhanced Logging:
Included error messages and stack trace printing to help debug potential issues.
Default Content-Type:
Set the Content-Type header explicitly to application/json to match API requirements.
Usage:
Ensure you have the Twitter API v2 Bearer Token set as an environment variable (BEARER_TOKEN).
Run the code. It will search tweets using the Full Archive Search endpoint based on the provided query. Adjust the query as needed.