Fetching tweets in a list + mediaKeys error
emin-grbo opened this issue · comments
While working on an app I encountered an issue while trying to retrieve URLs for images users posted in a tweet.
Specifically .mediaKeys(mediaFields: [\.url])
expansion in the array is the one that causes the issue.
The response we receive prints and UnknownError
which actually contains a model which seems ok?! 🤷♂️
The same request without the .mediaKeys value returns 👌.
Below is a method I used to retrieve the list tweets.
func fetchTwetsInList(listId: String) async -> TwitterAPIDataIncludesAndMeta<[Tweet], Tweet.Includes, Meta>? {
do {
let response = try await client?.getListTweets(listId,
fields: [\.text],
expansions: [.mediaKeys(mediaFields: [\.url]),
.authorId(userFields: [\.profileImageUrl]),
.referencedTweetsId],
paginationToken: nil,
maxResults: 50)
return response
} catch {
print(error)
}
return nil
}
Thanks for flagging @roblack! This is usually a decoding key error (i.e. I've written the name or type for a decoding key incorrectly) and can be debugged by trying to manually decode the response object in a breakpoint in the decodeOrThrow
method, which I'll do today to debug and fix this issue.
Weirdly, the only error I found was related to the ReplyAudience
struct, which revealed that the Twitter API returns mentionedUsers
rather than mentioned_users
. I wonder if this is actually the bug you experienced 🤔 I’ll push the fix and bump the version number (some other changes added) and you can test to verify!
great input @daneden!
I did manage to render some tweets but still getting odd errors.
It seems it depends if one of the tweets contains the model which causes the issues.
I will try to pinpoint it by examining the response as you noted above too, and see if I can come up with something.
As a note, the response with the issue was present ONLY when the same mediaKey is used. Without it the response reads fine.