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

Fetching tweets in a list + mediaKeys error #23

Closed
emin-grbo opened this issue May 20, 2022 · 3 comments
Closed

Fetching tweets in a list + mediaKeys error #23

emin-grbo opened this issue May 20, 2022 · 3 comments

Comments

@emin-grbo
Copy link
Contributor

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
    }
@daneden
Copy link
Owner

daneden commented May 21, 2022

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.

@daneden
Copy link
Owner

daneden commented May 21, 2022

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!

@daneden daneden closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2022
@emin-grbo
Copy link
Contributor Author

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.

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