Hello, I am new to Twitter’s API and the documentation for me is a little confusing. Is it possible to get tweets from users that mention a specific user such as users mentioning companies and getting information such as location/city, date, etc. by using Python, or is it only possible through the Postman API Platform? This is an example I found with Python however I am unsure if this would work with the recent changes to Twitter’s API.

Thank you in advance.

Postman is really only useful for debugging, for python there are these libraries: Twitter API v2 tools & libraries | Docs | Twitter Developer Platform i prefer GitHub - geduldig/TwitterAPI: Minimal python wrapper for Twitter's REST and Streaming APIs myself tweepy is also good.

That code example uses the GET statuses/user_timeline | Docs | Twitter Developer Platform endpoint - it can’t filter on tweet content, for that you need one of the search endpoints: which one depends on how far back in time you need to go: Twitter's search endpoints | Docs | Twitter Developer Platform

Or if you want tweets from the future, to capture them as they happen, Streaming API: Filtered stream introduction | Docs | Twitter Developer Platform

Generally the query will be like to:some_company this will get you replies and any time anyone posts a tweet to them. If you also want to get mentions it’s something like to:some_company OR some_company -from:some_company (because you don’t want tweet from the company itself)

1 Like

Many thanks, @IgorBrigadir. That makes much more sense now. I’m sorry, however, where exactly would the some_company - from:some_company go? Would it work in the example given below?

Thank you again.

That appears to be https://twittersearch.readthedocs.io/en/master/

One thing to keep in mind is:

It’s using the REST API in version 1.1 only.

So there’s no support for v2 endpoints. It looks like this may still work for you in that example like this:

tso.setKeywords(['to:some_company', 'OR', 'some_company', '-from:some_company'])

but i would double check that - i’ve never used this library and i’m just guessing based on the docs.

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