Using Tweepy to Access Twitter's Premium API
Asked Answered
W

2

8

I want to access Twitter's archive without being restricted by rate limits or number of queries. I don't mind paying for this, so my plan was to sign up for the premium package on Twitter's API platform. As I'm familiar with Tweepy, I had hoped to be able to access the API in my usual way.

However, it seems that the only way I can query the API with premium credentials in Python is through the Python Twitter Search API, which is basically a python wrapper for the premium service. The issue is that the authentication protocols for premium access are not the same as for the rate-limited free access. This is most annoying, as the searchtweets library that supports the Python Twitter Search API seems fairly primitive, and I can make practically no sense of the docs.

Does anyone know whether it is possible to use Tweepy to access premium tier for Twitter? It's kinda weird that the better tools only work on the free tier.

Wonderful answered 10/5, 2018 at 12:20 Comment(0)
R
8

That is not true. You can use the same credentials (assuming you get authorized by Twitter) for both the Standard Search and the Premium Search.

The TwitterAPI python wrapper supports both -- https://github.com/geduldig/TwitterAPI

from TwitterAPI import TwitterAPI
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)
r = api.request('tweets/search/fullarchive/:YOUR_LABEL',
                {'query':YOUR_SEARCH_TERMS})
for item in r:
    print(item)
Reset answered 19/5, 2018 at 23:27 Comment(2)
Thanks. Fair enough, seems I'm wrong on that point. My main question, though, is whether I can use Tweepy for the premium search, if my credentials allow that level of access. Any info on that?Wonderful
Premium is not mentioned in the Tweepy docs, so I believe not. That is why I pointed you to TwitterAPI instead.Reset
B
5

Tweepy now supports the premium API as discussed here. I had to install from github rather than pip. See the documentation for API.search_30_day and API.search_full_archive and the corresponding documentation for the premium search APIs.

pip install --upgrade git+https://github.com/tweepy/tweepy@master

The api is different. api.search becomes api.search_full_archive or api.search_30_day.

# premium search
tweets=tp.Cursor(api.search_full_archive,environment_name='you_env_name_here', query=search_words, fromDate=date_since).items(100)

# free search
tweets=tp.Cursor(api.search, q=search_words, lang="en",since=date_since).items(100)
Betook answered 2/10, 2020 at 16:41 Comment(2)
it is required to update the tweepy with pip install --upgrade git+https://github.com/tweepy/tweepy@master for using Twiter Premium APIGaucherie
Indeed, that is why I included it :) I should have made that more clearBetook

© 2022 - 2024 — McMap. All rights reserved.