How to Scraping by Tweepy

47 Views Asked by At

This is my first time using Tweepy to scraping my tweet, i use Google colab and i get stuck while make a query

# Define query
query = 'from:BarackObama -is:retweet'

# get max. 100 tweets
tweets = client.search_recent_tweets(query=query, 
                                    tweet_fields=['author_id', 'created_at'],
                                     max_results=100)

when i put this, the result is

Unauthorized                              Traceback (most recent call last)
<ipython-input-14-fbb05101b500> in <cell line: 5>()
      3 
      4 # get max. 100 tweets
----> 5 tweets = client.search_recent_tweets(query=query, 
      6                                     tweet_fields=['author_id', 'created_at'],
      7                                      max_results=100)

2 frames
/usr/local/lib/python3.10/dist-packages/tweepy/client.py in request(self, method, route, params, json, user_auth)
     96                 raise BadRequest(response)
     97             if response.status_code == 401:
---> 98                 raise Unauthorized(response)
     99             if response.status_code == 403:
    100                 raise Forbidden(response)

Unauthorized: 401 Unauthorized
Unauthorized

can you teach me how to fix? i tried to googling and most of it said to change the time, but i'm not quiet understand which time should i change.

0

There are 0 best solutions below