How to retrieve old tweets (beyond the most recent 3,200 tweets) from a specific user account on Twitter? - api

I have access to the Academic Research API. I am trying to retrieve old tweets from political candidates’ accounts during certain election campaigns (i.e., I would ideally specify begin and end dates). The timeline endpoint allows me to retrieve only the last 3,200 tweets of each of these accounts; but this falls short, since I cannot get any tweets from the desired election campaign period because it is too old in the timeline. I would ideally like to retrieve 3,200 tweets from a certain end date (the end of the election campaign). I have also seen the option of a Full archive endpoint, which would allow me to retrieve old tweets, but this does not directly enable (correct me if I am wrong) the targeting of specific users. Is there any additional option you would recommend to deal with this? Or would you rather directly retrieve each of the tweets using the IDs (although this would be too manual)?

Apparently the best way to do this is to use the Archive Search API. It is part of the premium API, so you first need to be granted an application with connection to the Academic Research API, and then opening a premium environment that lets you access the Archive Search API.
Once in the Archive Search API, you can specify dates (they are parameters of the request) and specific users with parameters within the query. An example here with twarc2 (Python): https://twittercommunity.com/t/twitter-api-timeline/171849/4?u=aguperonodo
In rtweet, this functionality can be implemented with the search_fullarchive function.

Related

Instagram API - Can they provide likes amount?

Need to work with the Instagram API
Need these types of data, when I search an Instagram Hashtag #
Get All recent posts with this hashtag
Get Comments_Count, Likes_Count
Account name (of post writer)
Image URL (of post)
URL of post
I tried to work with the Instagram Graph API, having a bit difficulty since its API looks quite different than other APIs, did you manage to find where they put it?
Here is the relevant reference for hashtags, but you can see that there are some significant restrictions on the endpoint.
https://developers.facebook.com/docs/instagram-api/guides/hashtag-search/
You can get data for 30 hashtags a week per Business or Creator account that has authorized your app, so the endpoint is not that useful outside of a few use cases.
If you don't need to track that many hashtags, I believe you can get all of the information EXCEPT the Account Name for the post creator. You would need to register and code an app that can pass review for the Instagram Public Content Access feature and the instagram_basic permission, and then the Business or Creator account would need to authorize your app (and keep it authorized).

How do I get all retweets or the retweeters of my own personal tweet?

I know you must be thinking that its impossible or its been asked already.
But I have 2 queries. The first is that by using Twitter API, using an access token of my own profile, can I get all (more than 100) the retweets of my own tweet? Not someone else's, as all previous questions at stackoverflow have been asked.
Because there's a difference in private and public tweet and getting data related to it.
Secondly, if we cannot get more than 100 retweets, then how does this app Pickaw (formerly Twrench) https://pickaw.com/en gets all the retweets even if they're more than 500 and the corresponding data?
Any ideas?
The Twitter API only provides access to up to 100 Retweeters (IDs for users that RT'd a Tweet), regardless of whether this is your owned Tweet, or another one.
As for a specific app, it is only possible to speculate, unless the source code was Open Source and available. I would suggest there are two ways to get all the Retweets:
pay for premium or enterprise search access, and use the advanced PowerTrack rules to find Retweets of a specific Tweet ID;
use the Account Activity API webhooks to track whenever a user's Tweet is Retweeted. Not that this would only work in a real-time tracking case; you wouldn't be able to check historical Tweets.

Create a new scheduled Tweet via the API

I looked into their documentation and they do provide this feature:
https://support.twitter.com/articles/20170532-scheduled-tweets#How_to_create_a_new_scheduled_Tweet
But would it be possible to do this through the API (I didn't find any reference to this or attributes).
There's no way to do it with the Twitter API. You have two choices:
Either tell your code to run at a specific time (using cron or similar), or check what the time is before posting.
Use a third party service like Buffer - https://bufferapp.com/developers/api
This can be done using Twitter Ads API(scheduled tweets api).
From the api doc,
Scheduled Tweets allow an advertiser or user to create a Tweet that can be scheduled to go live at a later date. In addition to being able create and manage these Tweets, the API allows the ability to associate these Tweets with a line item, to be promoted once the Tweet goes live. This allows advertisers to stage create native Tweets and plan their campaign creatives in advance of any key initiatives. For example, staging a Tweet creative to live immediately upon a new product announcement.
The full set of functionality provided by the Scheduled Tweets API endpoints are listed below:
Create, modify and view newly scheduled Tweets
Associate a Scheduled Tweet with a line item
Query and manage existing scheduled Tweets
Once a Scheduled Tweet goes live, retrieve the live Tweet id
Complete details can be found here
You can create a Scheduled Tweet for the account's full promotable user (default) or the user specified in the as_user_id parameter.
https://developer.twitter.com/en/docs/ads/creatives/api-reference/scheduled-tweets#post-accounts-account-id-scheduled-tweets
There is a limit of 5 user per account... even with a developer account you have to request acces to that API.

Copying all foursquare venues of a city without violating API's usage rules?

Scope:
I am starting an application that will need a very rich database of venues within a certain city right on it's start so i thought that scraping foursquare's database would be a great idea, but seems like scraping volumes over 1000 venues is considered forbidden according to it's usage / data retention policy
My Needs:
Basically, what i want to achieve is a way to allow users to search their favorite venues and receive notifications from them, so having all the venues of this city would be perfect for me, allowing me to store the relationship USER XXX FOLLOWS YYY VENUE
Problem:
Since i can't "copy" / "transfer" all the foursquare venues of a given city to my own database, what can i do to actually "store" the data i need for my own use ?
Is there any workaround for this ? (I don't mean ilegal actions, but some clever use of the API instead).
You can force your users to connect with 4sq (with oauth), then retrieve the data you need using oauth tokenwith 4sq api, which does not violate the rules and put any limits to the amount of data.
You can store user's 4sq id and the venue ids they follow in your own db and retrieve the details as needed. Am I missing sth with this flow?

Design for getting Twitter friends list for large user base and managing rate limiting

Assume there's a mobile app and a server.
I have question about rate limiting and hoping someone can give some advice on a design as I'm banging my head on how to navigate around rate limit. There must be something I"m missing because the 150 unauthenticated rate limit per IP per hour is extremely low.
Imagine the scenario I want to build is the following (simplified into a trivial example for this discusion). Assume user is signed into Twitter for this entire discussion to remove discussion about oAuth.
Mobile talks to our service to show users twitter friends list. Every time the mobile app is loaded, it will show the entire friends list, and highlighting the new friends that were added within the last 2 days.
That's it. But the trick is that I want to ensure that the friends list is always up to date in the client, which means our server has to have the most recent up to date friends list.
Periodically, I want my server to automatically scan the Twitter friends list for every user of my app to see if new friends have been added.
Our initial design was getting our server to do all the work with this flow:
New User signs in on client, gives access token to server
Server makes call to Twitter REST APIs to get initial friends lists
Server stores the Twitter Friends IDs and shows responds to the client with that list.
Periodically (e.g. every 48 hours), server checks Twitter REST APIs for friends list for each user and compares it to our cached Twitter friends list we have for them to see who is new and to highlight in the mobile app.
The good thing about this is that all the interaction with twitter to get friends list, compare and peridiocally refresh is on the server. Mobile client just makes a single call to my server and gets friends list.
The problem with this design is that it will work for a single user, but since the rate limit is 150 per hour on un-authenticated calls, I will hit my limit as soon as 151 users user my service (which has a fixed IP).
The only solution I can see is to have the client do the work for each user, then send me the friends list which my server caches. This takes care of Step #2 above. However, for Step #4, I'd have to build something into the client to auto refresh twitter friends and send back to the server.
This is super clumsy to have the client involved at all in this Twitter friends list operation.
At first I thought I was crazy and the public unauthenticated APIs like getting friends lists wouldn't be subject to rate limiting. However, according to their docs, it is.
Am I missing something obvious or is the only way to solve this is to put heavy logic into the client?
With whitelisting gone for those that aren't grandfathered or Twitter business partners, I don't think you have any alternative but to have your mobile app do the Twitter API calls from the handset.
Having the handset call Twitter isn't a bad thing by any means. Pretty much every Twitter client in the world does it. One benefit will be that the user will be authenticated to Twitter, and thus her full 350 calls per hour will be available to you. Keep in mind, however, that you should minimize your calls since the user may have other Twitter-aware applications installed on her handset eating into your call allotment, and vice versa.
Now to the solution. The way I would implement your use case would be to first fetch the complete list of friends for your user by calling the friends/ids method.
http://api.twitter.com/1/friends/ids.json?screen_name=yourUsersName
The above call will return the most recent 5,000 friend IDs, in order followed, for #yourUsersName. If you want to fetch more friend IDs than the first 5,000, you'll need to specify the cursor parameter to initiate paging.
Next, I would check the latest list of friends we just fetched against the list on the handset, syncing them by removing any IDs that are no longer present, while adding any that are new.
If we only need the friend IDs, then we're done at a cost of one API call per 5,000 friend IDs. If, however, we need to get user info for these new friends as well, then I would call users/lookup and pass in the list of all new users that we discovered while syncing friend IDs. You can request up to 100 user objects at a time.
http://api.twitter.com/1/users/lookup.json?user_id=123123,5235235,456243,4534563
You user must be authenticated in order to make the above request, but the call can fetch any Twitter user profiles you wish -- not just those that are friends of the authenticated user.
So, let's say for example that a user has 2,500 friends and has never used your app before. In that case, she would burn one call to fetch all of the friend IDs, and 25 calls for her friends' information. That's not too bad to get the app populated with data.
Subsequent calls should be more streamlined with probably only two calls burned (one for the IDs, and one to get the new friends).
Finally, once the data has been updated on the handset, the deltas for the IDs and user data can be gathered up and pushed to your server.
It may even be possible that your server application won't even have to interface with Twitter at all, and that should alleviate the 150 user limit you are encountering.
Some final notes:
Be sure to note in your app's privacy policy that you sync your user's friend list with your server.
I recommend specifying JSON as the return format for all Twitter API calls. It is a much more lightweight document format than XML, and you will typically transfer only about 1/3 to 1/2 as much data over the wire.
Pick a Twitter framework appropriate for your mobile device and your programming language. Twitter access is a commodity these days, and there's little to no reason to reinvent how to access the Twitter API.
I answered a similar question about an approach for efficiently fetching followers here.
Since you are making request on behalf of users you should make those requests be authenticated as those users. Then requests will count against each users own pool of 350 requests/hour.