Title: Add Support for Handling Long Tweets using note_tweet Field
Description
For long tweets, the default Tweet.text field only contains the initial part of the tweet, with the rest being replaced by "...".
To handle the issue, twitter recently introduced a feature to obtain the full text of long tweets by including the note_tweet field in the request parameters when fetching tweets.
Our library should support this new API feature.
Steps to Reproduce
Make a request to the Twitter API for a tweet longer than 280 characters.
We can see in the response the tweet text is truncated, with the remainder replaced by "...".
Example Request:
curl -X GET "https://api.twitter.com/2/tweets/1729154466539266176" -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response:
{
"data": {
"edit_history_tweet_ids": ["1729154466539266176"],
"id": "1729154466539266176",
"text": "A Big Uranium SHORTAGE is coming in the next decade\n\nUranium mining has significant long-term potential\n\nMiners have run up by almost 50% over the last few months\n\nWe JUST downgraded our Uranium Miners rating from Buy to Neutral\n\nIf you have recently accumulated URA, it may be… https://t.co/pFmyrGoyqv https://t.co/dw2PGshiQr"
}
}
Expected Behavior
Twitter has introduced a new feature to obtain the full text of long tweets by including the note_tweet field in the request parameters. By adding note_tweet to twitter_field, the response will include the complete tweet in note_tweet.text.
curl -X GET "https://api.twitter.com/2/tweets/1729154466539266176?tweet.fields=note_tweet" -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response:
{
"data": {
"edit_history_tweet_ids": ["1729154466539266176"],
"text": "A Big Uranium SHORTAGE is coming in the next decade\n\nUranium mining has significant long-term potential\n\nMiners have run up by almost 50% over the last few months\n\nWe JUST downgraded our Uranium Miners rating from Buy to Neutral\n\nIf you have recently accumulated URA, it may be… https://t.co/pFmyrGoyqv https://t.co/dw2PGshiQr",
"note_tweet": {
"text": "A Big Uranium SHORTAGE is coming in the next decade\n\nUranium mining has significant long-term potential\n\nMiners have run up by almost 50% over the last few months\n\nWe JUST downgraded our Uranium Miners rating from Buy to Neutral\n\nIf you have recently accumulated URA, it may be best to take some profit or hold on to your position instead of adding more\n\nWe're optimistic in the long term but not currently favorable to enter the trade\n\nGet a weekly update on Uranium Miners as part of our Asset Ratings\n\nEach week, we provide our members with an overview of the most attractive assets to long or short\n\nCyber Week is the best deal of the year to join Game of Trades\n\nGet 40% off our membership + a FREE 7-day trial\n\nDon't miss out on this opportunity!"
},
"id": "1729154466539266176"
}
}
Solution Proposed:
To support the handling of long tweets, modify the TweetField structure and the Tweet structure in our library:
Add TweetFieldNoteTweet as an available TweetField when submitting a request:
TweetFieldNoteTweet TweetField = "note_tweet"
Update the Tweet structure to include the NoteTweet field:
I have made the necessary changes and completed testing to ensure the solution works as expected. The test code and results are provided in the linked pull request.
Title: Add Support for Handling Long Tweets using
note_tweet
FieldDescription
For long tweets, the default
Tweet.text
field only contains the initial part of the tweet, with the rest being replaced by "...".To handle the issue, twitter recently introduced a feature to obtain the full text of long tweets by including the
note_tweet
field in the request parameters when fetching tweets.Our library should support this new API feature.
Steps to Reproduce
Make a request to the Twitter API for a tweet longer than 280 characters.
We can see in the response the tweet text is truncated, with the remainder replaced by "...".
Example Request:
Response:
Expected Behavior
Twitter has introduced a new feature to obtain the full text of long tweets by including the
note_tweet
field in the request parameters. By addingnote_tweet
totwitter_field
, the response will include the complete tweet innote_tweet.text
.Our library should support this new API feature.
Reference:
How do I get extra long tweet text via V2 api? - Twitter API / Twitter API v2 - X Developers
GET /2/tweets/:id | Docs | Twitter Developer Platform (x.com)
GET /2/tweets/search/recent | Docs | Twitter Developer Platform (x.com)
Example Request:
Response:
Solution Proposed:
To support the handling of long tweets, modify the
TweetField
structure and theTweet
structure in our library:Add
TweetFieldNoteTweet
as an availableTweetField
when submitting a request:Update the
Tweet
structure to include theNoteTweet
field:Pull Request related:
I have made the necessary changes and completed testing to ensure the solution works as expected. The test code and results are provided in the linked pull request.
Pull Request: PR #313
As a newcomer to the open-source community, I am open to feedback and suggestions to improve this contribution. Thank you!