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

expansions missing and example #89

Open
tobiasgrossmann opened this issue Jul 29, 2021 · 1 comment
Open

expansions missing and example #89

tobiasgrossmann opened this issue Jul 29, 2021 · 1 comment

Comments

@tobiasgrossmann
Copy link

let tweetsRawData = await client.get( 'users/1407591434660761602/tweets', { tweet: { fields: ['attachments,created_at,lang,text'], }, media: { fields: ['preview_image_url,type,url'] } }, );

Does not the create the to be expected call to:
https://api.twitter.com/2/users/1407591434660761602/tweets?tweet.fields=lang&**expansions**=attachments.media_keys&media.fields=preview_image_url,url

Result is this:
https://api.twitter.com/2/users/1407591434660761602/tweets?tweet.fields=attachments%2Ccreated_at%2Clang%2Ctext&media.fields=preview_image_url%2Ctype%2Curl

Also a "hint" in the documentation, that Twitter sends the "inclues" in a 2nd JSON Part would be nice.

@brandongregoryscott
Copy link
Contributor

@tobiasgrossmann The Twitter V2 API does not support arrays out of the box - you would need to join the array into a CSV string yourself, first.

// API expects a CSV string
{ tweet: { fields: 'attachments,created_at,lang,text', }, media: { fields: 'preview_image_url,type,url' } }
// Array.join() works too
{ tweet: { fields: ['attachments', 'created_at', 'lang,text'].join(), }, media: { fields: ['preview_image_url', 'type', 'url'].join() }

See this repl for an example: https://replit.com/@brandongscott/twitter-v289

Not to spam my own library here, but I have built some functions on top of this one to ease consumer use. It provides TypeScript definitions as well as automatic Array -> string conversion for these request parameters. https://github.com/brandongregoryscott/ts-twitter-provider#getting-started

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