Get who retweeted me using twitter apis - twitter

I want to get users who retweeted my tweets
$tweets2 = $connection->get("https://api.twitter.com/1.1/statuses/retweets_of_me.json");
Gives me list of my tweets which are retweed by other.
But it does not provide me details about who retweeted it. Any way to do this?
CAn I get this details using tweet ID?
In version 1.o
https://api.twitter.com/1/statuses/21947795900469248/retweeted_by.json
it was there but not present in version 2.:
I tried this:
https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json
but does not show anny response
Any idea or help is appreciated.
Scenaraio is like this:
user1 retweets me 5 times, user2 retweets me 7 times, that means I had 12 retweets.
User1 has 500 followers, user2 has 100 followers, that means my retweet reach was 5x500 + 7x100 = 3200. So, on my webpage, I would like to see 12 retweets and 3200 retweet reach.

Use this api https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me to get the ID of the users.
Pass comma-separated user_id or screen_name to this https://dev.twitter.com/docs/api/1.1/get/users/lookup to get the info about the users.

Related

Twitter search : avoid keyword matching replied username

The body of a tweet reply is having a list of #username at the beginning.
When you search for a keyword, it can match a username in this list.
For example, searching keyword will match:
Tweet A :
This is an exemple tweet speaking about keyword
Tweet B : (a reply tweet)
#keyword Speaking about random topic
There is multiple solution to exclude tweet replies using -filter:replies or exclude:replies, but it will remove all replies. It won't be possible to match tweet like :
Tweet C :
#username Reply speaking about keyword
Is it possible to search a keyword only within tweet content, without matching to a name in front of a reply tweet ? Having a query to match only Tweet A and C.
Try
[keyword] -from:[keyword] -#[keyword] -to:[keyword]
Where [keyword] is, of course, any keyword you choose.
-from:[keyword] will exclude tweets from the #keyword user
-#[keyword] will exclude tweets mentioning the user #keyword
-to:[keyword] will exclude tweets replying to the user #keyword

Is it possible to search Twitter Users by number of followers?

I would like to find public users on Twitter that have 0 followers. I was thinking of using https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search, but this doesn't have a way to filter by number of followers. Are there any simple alternatives? (Otherwise, I might have to resort to using a graph/search based approach starting from a random point)
Well you didn't specify what library you are using to interact with the Twitter API. But regardless of which technology you're using, the underlying concept is the same. I will use tweepy library in python for my example.
Start by getting the public users using this. The return type is a list of user objects. The user object has several attributes which you can learn about here. For now we are interested in the followers_count attribute. Simply loop through the objects returned and check where the value of this attribute is 0.
Here's how the implementation would look like in python using tweepy library;
search_query = 'your search query here'
get_users = api.search_users(q = search_query)#Returns a list of user objects
for users in get_users:
if users.followers_count ==0:
#Do stuff if the user has 0 followers
Bird SQL by Perplexity AI allows you to do this simply: https://www.perplexity.ai/sql
Query: Users with 0 followers, and 0 following, with at least 5 tweets
SELECT user_url, full_name, followers_count, following_count, tweet_count
FROM users
WHERE (followers_count = 0)
AND (following_count = 0)
AND (tweet_count >= 5)
ORDER BY tweet_count DESC
LIMIT 10

Get posts from different users

So, i have 100 posts from 10 users, and i want to get a collection of 5 posts, but always from different user.
So Post.where(active: true).order(:created_at).limit(5)... works.
Any help?
You can select distinct User IDs:
Post.select("DISTINCT(user_id)").where(active: true).limit(5)

twitter API limiting tweets to one day, tweepy

I'm trying to pull data from Twitter over a month or so for a project. There are <10000 tweets over this time period with this hashtag, but I'm only seeming to get all the tweets from the current day. I got 68 yesterday, and 80 today; both were timestamped with the current day.
api = tweepy.API(auth)
igsjc_tweets = api.search(q="#igsjc", since='2014-12-31', count=100000)
ipdb> len(igsjc_tweets)
80
I know for certain there should be more than 80 tweets. I've heard that Twitter rate-limits to 1500 tweets at a time, but does it also rate-limit to a certain day? Note that I've also tried the Cursor approach with
igsjc_tweets = tweepy.Cursor(api.search, q="#igsjc", since='2015-12-31', count=10000)
This also only gets me 80 tweets. Any tips or suggestions on how to get the full data would be appreciated.
Here's the official tweepy tutorial on Cursor. Note: you need to iterate through the Cursor, shown below. Also, there is a max count that you can pass .items(), so it's probably a good idea to pull month-by-month or something similar and probably a good idea to sleep in between calls. HTH!
igsjc_tweets_jan = [tweet for tweet in tweepy.Cursor(
api.search, q="#igsjc", since='2016-01-01', until='2016-01-31').items(1000)]
First, tweepy cannot bring too old data using its search API
I don't know the exact limitation but maybe month or two back only.
anyway,
you can use this piece of code to get tweets.
i run it in order to get tweets from last few days and it works for me.
notice that you can refine it and add geocode information - i left an example commented out for you
flag = True
last_id = None
while (flag):
flag = False
for status in tweepy.Cursor(api.search,
#q='geocode:"37.781157,-122.398720,1mi" since:'+since+' until:'+until+' include:retweets',
q="#igsjc",
since='2015-12-31',
max_id=last_id,
result_type='recent',
include_entities=True,
monitor_rate_limit=False,
wait_on_rate_limit=False).items(300):
tweet = status._json
print(Tweet)
flag = True # there still some more data to collect
last_id = status.id # for next time
Good luck

Tweepy: How can I get more than 20 tweets from a user?

According to their docs:
API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page])
Returns the 20 most recent statuses posted from the authenticating user or the user specified. It’s also possible to request another user’s timeline via the id parameter.
So how can I get more than 20 tweets from a person's timeline? The docs do not show how...Does that user need to be authenticated?
You can make use of pages parameter in API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page]). For page value 1, you will get a set of latest 20 tweets from the user timeline and then in further iteration, when we increase the value of page = 2 then the method returns other 20 tweets which are older from the the oldest tweet received from page 1, You can think of this as:
Suppose you have 120 tweets in the account (1st tweet being the oldest and 120th tweet being the latest), then:
page = 1 would return (100, 120]
page = 2 would return (80, 100]
... and so on
I hope you got the concept of pages now it's time to implement those things.
no_of_pages = int(raw_input("Please enter the number of tweets: "))
for i in xrange(no_of_pages):
API.user_timeline("#anmoluppal366", page = i)
You can also use the max_id parameter. Something like
r0 = api.user_timeline("#donaldtrump") # gives 20 latest tweets
idlast = r0[-1].id # the last id of these 20
r1 = api.user_timeline("#donaldtrump", max_id = idlast) # next 20 tweets older or same age as idlast

Resources