How to get headstaged tweets from a user list

Is there a way to get all the tweets from the list of profiles (3) that are tagged with a specific #hashtag in a single Twitter API call using 1.1?

If not, obviously, I would extract a hundred tweets from each user and filter out those that do not have #hashtag .. but this is not very efficient, right?

Thank you in advance

+1
source share
1 answer

Note. I updated the library , so I suggest you use the new updated version before trying to do this - I did this so you do not need to manually encode each individual character.

This page shows you how to use the search, and has several operators down at the bottom of the page. One of them is the OR operator:

Getting Tweets for Multiple Users

OR - either this or that

love OR hate - containing either "love" or "hate" (or both)

From - from this user

from:twitterapi sent from the user @twitterapi

So, armed with the above knowledge, I assume that your request will look like this:

Translated to GET request:

?q=from:user1+OR+from:user2


Getting tweets for specific hashtags

So how do you get tweets for multiple users. The next step you want is certain hashtags.

#haiku - containing the hashtag "haiku"

What is individually translated into the correct format becomes:

?#haiku (or% 2C haiku, depending on the / urlencoding library used)


Combining above

The standard AND operator is as follows:

twitter search - containing both "twitter" and "search". Default operator

To request receipt:

?twitter+search

So let me combine all this!

?q=#hashtag1+#hashtag2+from:user1+OR+from:user2

And since you are using my lib , here is the code for this:

 $url = 'https://api.twitter.com/1.1/search/tweets.json'; $requestMethod = 'GET'; $getfield = '?q=#hashtag1+OR+#hashtag2+from:username1+OR+from:username2'; $twitter = new TwitterAPIExchange($settings); $json = $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); var_dump(json_decode($json)); 
+8
source

Source: https://habr.com/ru/post/1490304/


All Articles