Is lang operator working as intended?

search

#1

I just purchased premium api access and right now trying to get it to work with the lang operator.

I am using endpoint https://api.twitter.com/1.1/tweets/search/30day/<…and a valid label here>

Trying out a query that looks like “lang:sv (apple watch) OR tele2” just gives me results in any available language.

However … using a browser to search for it here: https://twitter.com/search?f=tweets&q=lang%3Asv%20(apple%20watch)%20OR%20tele2&src=typd

works perfectly fine…

Am I missing something in the premium API call??


#2

Hej @abstractitsthlm! I believe the issue is with the way you’re running the request. Could you send me your request (with keys/tokens redacted)?

Also, check out this Premium Search tutorial on how to quickly build and run a query using cURL or Twurl.

Hamza


#3

Hi @Hamza

This pretty much replicates the issue… just replace the environment and token placeholders.

curl --request POST \
  --url https://api.twitter.com/1.1/tweets/search/30day/<ENV>.json \
  --header 'authorization: Bearer <TOKEN>' \
  --header 'content-type: application/json' \
  --data '{
                "query":"lang:sv tele2 OR (apple watch)",
                "maxResults": "100",
                "fromDate":"201901101000"
                }'

It is a bit unclear from the API documentation exactly how the query should be created in cases like this.
Especially since the query from above actually works perfectly fine on twitter.com.


#4

Hmm, when I run the exact same query I’m able to successfully get the data I request, which leads me to believe the issue may be with your command line only displaying a certain amount of data. Have you tried to run the request with Postman or Insomnia?


#5

Sorry, I am not sure if you understood my issue.
Did you check the data you got back? What languages are the posts marked as?
I do get get data back according the terms, however I get too much. I get tweets that are in English or other languages too, but I specified that I wanted only Swedish results. The lang operator doesn’t seem to work as I would have expected in this case.


#6

@abstractitsthlm - can you try running the request (I modified the data field):

  --url https://api.twitter.com/1.1/tweets/search/30day/<ENV>.json \
  --header 'authorization: Bearer <TOKEN>' \
  --header 'content-type: application/json' \
  --data '{
                "query":"(tele2 OR (apple watch)) lang:sv",
                "maxResults": "100",
                "fromDate":"201901101000"
                }'

This should work, but let me know if you have any issues.


#7

One thing to note here is that the premium and enterprise search syntax is based on our PowerTrack query language, and is explicitly not the same as the query you can type on twitter.com. Broadly speaking the standard APi does support the website syntax, but the same does not apply on premium search endpoints.


#8

yup, that is what I am using already since that gave me more relevant result.

Still would be great to have this clarified in the API docs…


#9

Thank you for the feedback, @abstractitsthlm. Our goal is to make our documentation more accessible, and your feedback is always appreciated. :100:


closed #10

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