twitter-api-java-sdk icon indicating copy to clipboard operation
twitter-api-java-sdk copied to clipboard

Getting an IllegalArgumentException when deserializing JSON response to create tweet

Open broadbear opened this issue 2 years ago • 0 comments

Getting an IllegalArgumentException when deserializing JSON response to create tweet. It looks like the TweetCreateResponseData class doesn't contain fields present in the create tweet response JSON since Sept 20, 2022:

https://developer.twitter.com/en/docs/twitter-api/fields

By default, the Tweet object only returns the id and the text fields, and for Tweets created since September 29, 2022, the edit_history_tweet_ids field.

Expected behavior

CreateTweetRequest instance is created and populated with tweet information from the JSON response to create a tweet.

Actual behavior

Getting an IllegalArgumentException when deserializing JSON response to create tweet. The error seems to be related to a newish JSON field that was added to the response to create tweets via the TwitterApi.tweets().createTweet() api call. The exact error is:

java.lang.IllegalArgumentException: The field edit_history_tweet_ids in the JSON string is not defined in the TweetCreateResponseData properties. JSON: {"edit_history_tweet_ids":["1671964017076883456"],"id":"1671964017076883456","text":""Ahoy!""}

Steps to reproduce the behavior

Use the twitter api to create a tweet and attempt to deserialize the response directly to a TweetCreateResponse object.

TweetCreateResponse result = apiInstance.tweets().createTweet(createTweetRequest);

broadbear avatar Jun 22 '23 19:06 broadbear