I want to find how many tweets of user A did their specific follower B favorited. Is there any way to do this using either Python's tweepy or R's rtweet?
Many thanks!
You can do this, but it is a bit complicated.
You need to use GET favorites/list
This will let you get up to 200 Tweets that User B has liked. You would then have to search through the returned Tweets to see which ones were posted by User A.
The Tweepy documentation for favorites tells you how to do this:
tweets = API.favorites("edent")
Will get you all the tweets I've liked.
Related
I have access to Twitter API for Academic Research, and I'd like to get the follower count on a given date of a user, or at the time of a tweet.
The doc mentions that "This fields parameter enables you to select which specific user fields will deliver in each returned Tweet.", so I assumed that by adding public_metrics to the users.field, the number of followers can be seen in each returned Tweet, however, in each returned Tweet, I can only see user_id. https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference.
Is it even possible to achieve what I want with Twitter API for Academic Research? Is there any other approach to make it?
Thank you so much.
You cannot get the follower count on a specific date; it will always be the count at the time you make the API call.
You may need to add expansions to your API call in order to receive the values you are trying to pull out.
I have a general question regarding twitter APIs in python - is there a way to get the total number of times a particular word, or phrase were tweeted?
Thanks in advance.
You can't get that for the life of Twitter. However, you might be able to the search API to get an idea of how many times over the last 2 weeks, which is the approximate max amount of time the search API goes into the past:
auth = tweepy.auth.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
search_results = api.search(q="<your word>")
Then count the number of tweets you get back for an approximation.
For more info, look at the Tweepy Search API. Also, look at Tweepy Cursors for getting more than the default count of tweets.
Here is my example query. It specifies that Tweets must be:
Written in English
Tweeted between 23Jan2010 and 24Jan2010
Have at least 100 "favorites" (likes)
My idea is to use something like the binary search algorithm to narrow down the minimum number of likes the Tweet has. Once only one Tweet is returned by a query, I'll know it is the Tweet with the most likes. The problem is, min_faves--the value that specifies the minimum number of likes--doesn't seem to work. Look at this query. It specifies min_faves as 100. As you can see, this Justin Bieber Tweet appears. It has 1.6k likes. Now, when I attempt to increase the min_faves value to 300 (to narrow down the most liked Tweet), the Justin Bieber Tweet is excluded! I don't know if I am not understanding the query system correctly, or if it is not working, but this seems incorrect. The Justin Bieber Tweet should show up, as it has more than 300 likes. This is just one example of how it doesn't seem to work.
Perhaps this is ocurring because, within the specified time range, the Justin Bieber Tweet did not have enough likes to meet the requirements. This would be very good for me, as I am trying to find the most liked Tweet on that particular day, and not the Tweet with the most likes right now that happens to have been posted on that particular day.
But, I do not believe this is the case. For instance, this query includes 3 Tweets from "Rev Run" when min_faves is set to 249, but returns 0 Tweets when min_faves is set to 250. I doubt that these Tweets all had exactly 249 likes on that day (as implied by these symptoms).
Does anyone either:
Understand why these results occur and how I can use this method to find the most liked Tweet of a particular day
Know of a better, alternative way I can find the most liked Tweet of a particular day
Thank you all
#sinanspd requested an example from 2018:
Here is a search with min_faves at 300k. It includes a post with 769k likes and a post with 479k likes. When the query's min_faves is bumped up to 400k neither are returned.
I try to make social network (like instagram )
User have posts and followers etc
I want for home feed show posts just from users i follow.
User have array with ids of users he follow. So idea is to query from colloection “Posts” where id is equal to one of ids and sort them by timestamp and limit them.
I could make for loop for each in following array but this will be unusable for more than 100 following users.
Edit how I think it could be solved
Hello i dont know if im doing it right but here is my solution for social network like instagram or any other where one user follow other users and have feed from their posts ordered by date.
Each user have its own Collection Timeline where are posts references (postId, createdAt, createdBy) that user should see at his feed, when user start following other user it will put all his posts to feed. For display feed I just call on User timeline, sort it by date and request just 25 of them.
When user start the app I loop trough all followers and request their posts younger than lastTimeline timestamp from their posts collection if they have any I add them to timeline.
I would be happy for your opinion.
You can loop through all the followed user ID and then request the first 5 posts of each one.
Or use some kind of paging
LinqToTwitter: How to search tweets of users which i follow?
Using below code, I m getting results for all pubic tweets but i want to query tweets of users which i follow?
var twitterCtx = new TwitterContext(auth);
var searchResults =
from search in twitterCtx.Search
where search.Type == SearchType.Search
&& search.Query == txtQuery.Text
select search;
var searched = searchResults.SingleOrDefault();
Though the Twitter API doesn't offer the option you need, there are a couple things that might come close to what you want: a 'from' operator or a stream.
You can visit the Twitter Search page and view the list of operators that you can include in your LINQ to Twitter Query. One of these operators is 'from'. This appears to be only a single user, but it sounds like you want all of your followers. Anyway, you can experiment on the Twitter Search page to see what results you get and then translate that into the LINQ to Twitter Query.
Another approach might be to use a Filter Stream. It has a Follow property that takes a comma-separated list of users. With the Search above, you're doing request/response. However, streams are different in that you open the connection and listen for a long time, processing responses as they arrive.