How do I define the language of the tweets

Hello!

How can I set the Twitter search to be in a specific language? I mean, so that only tweets in French?

Hi @cryosat-cosmonaut-15 I see that you need to add query with the param lang:fr

1 Like

@ bpricilla
thanks for the sharing, it’s really helpful, but just one more question, while im following it, where should i add this param?

Hi @project66610, I wanted to check with you if you had found a way to add the language parameter in the end? If that’s the case, I would be love to know how you did it.

1 Like

hi, it’s good to hear from people who are having the same questions however, i have not found a way to do so. Are you able to have any new insights regarding this?

I’m only just starting with Postman and I haven’t used the Twitter API yet. I hope that I can share more insights once I have started playing with it. I also found this video which I think will help me get started: Postman Tutorial - Get Started With Twitter API In Few Minutes - YouTube. I’m not sure it does provide a direct answer to your question though. Let’s keep each other updated!

based on my memory, this video doesn’t cover this content, but yeah. we definitely keep each other updated!

1 Like

Hey :wave:

There used to be a way to filter by language in the Twitter API v1 but it has since been deprecated.
With the v2 API, what you can do is:

  • add the lang field to your request so the value is added to the response

  • write a Test script that filters the tweets in the response by only getting the ones where lang is fr, then save it to a collection variable

let tweets = pm.response.json().data

let tweets_fr = []
tweets.forEach(function(tweet) {
    if(tweet.lang == "fr")
        tweets_fr.push(tweet.text)
})

pm.collectionVariables.set("tweets_fr", JSON.stringify(tweets_fr))

Here’s what’s saved in the collection variables afterwards:

Feel free to fork this collection, or copy the code from here directly :arrow_right: Postman

2 Likes

thank you very much for sharing the idea! It’s definitely helpful. I will give it a try.

2 Likes

From my testing, you can definitely use e.g lang:fr within the query, the only problem may be if you have multiple query terms already, then it gets a bit confused … so you might need to use brackets - for example :

foo OR bar OR baz -is:retweet lang:en

doesn’t work as you’d expect, and you get any old language back - so perhaps it’s doing foo OR bar OR “baz -is:retweet lang:en” ?

Anyway, fixing it (for me) is :

( foo OR bar OR baz ) -is:retweet lang:en

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.