1

I am on a developer account where for the last year I have been developing a bot. Originally I used v1.1 to make tweets and now with v2 I have updated my code to make tweets successfully.

Now I am try to do searches using search_recent_tweets. The full search I have read is restricted to Academic access which I don't have for my bot. But I should be able to get search_recent_tweets to return results?

When I use client.search_recent_tweets from python code with tweepy, I get a 401 Unauthorized Error and I wonder why since my credentials work for making tweets. My search code is:

from config_v2 import create_client

# Create Client object
client = create_client()

query = 'point_radius:[25.11 -82.054 1km]'
dict_object = client.search_recent_tweets(query=query, max_results = 10, start_time='2022-12-06T05:00:00Z')

with open('geo_test.txt', 'w') as f:
    for k in dict_object.keys():
        f.write(k + '\t' + dict_object[k] + '\n')

My authentication code:

client = tweepy.Client(
    consumer_key=CONSUMER_KEY,
    consumer_secret=CONSUMER_SECRET,
    access_token=ACCESS_TOKEN,
    access_token_secret=ACCESS_TOKEN_SECRET
)

1 Answers1

1

There are two separate problems with the above code:

First to get past the 401 Error, we can add the BEARER TOKEN as well into the instantiation of the Client. This will allow basic search operations to take place.

Second, in my case I would get a 400 Bad Request message upon doing the above. There is so much conflicting information on the web, but it appears the point_radius is an Enterprise filter (meaning it costs money and is not automatically included to a developer) and as I am not an Enterprise user, it is not available to me. But, the basic query like @twitterapi will work for whatever that is worth. Too bad, because I was especially interested in the Geo capabilities of the Twitter API and that was the whole point of using it.