You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've set a code that I've found on one tutorial. And after changing some parts because of being outdated I still get into a problem. The problem is that I check if a tweet is already liked but some how the conditional if not tweet.favorited doesn't work.
Here the code:
import tweepy
import time
auth = tweepy.OAuthHandler("Consumer Key here", "Consumer Secret here")
auth.set_access_token("Access Token here","Access Token Secret here")
api = tweepy.API(auth, wait_on_rate_limit=True)
search = "#crypto OR #nft"
nrTweets = 500
for tweet in tweepy.Cursor(api.search_tweets, search).items(nrTweets):
try:
if not tweet.favorited:
tweet.favorite()
print("Tweet Liked")
time.sleep(240)
except tweepy.errors.TweepError as e:
print(e.reason)
except StopIteration:
break
And here the response I get on the terminal:
zaesar@zaesar-X541UV:~/Escritorio/coding/python-twitter-bot$ python3 twitter.py
Tweet Liked
Tweet Liked
Tweet Liked
Tweet Liked
Tweet Liked
Tweet Liked
Traceback (most recent call last):
File "/home/zaesar/Escritorio/coding/python-twitter-bot/twitter.py", line 17, in <module>
tweet.favorite()
File "/home/zaesar/.local/lib/python3.9/site-packages/tweepy/models.py", line 371, in favorite
return self._api.create_favorite(self.id)
File "/home/zaesar/.local/lib/python3.9/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "/home/zaesar/.local/lib/python3.9/site-packages/tweepy/api.py", line 925, in create_favorite
return self.request(
File "/home/zaesar/.local/lib/python3.9/site-packages/tweepy/api.py", line 259, in request
raise Forbidden(resp)
tweepy.errors.Forbidden: 403 Forbidden
139 - You have already favorited this status.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/zaesar/Escritorio/coding/python-twitter-bot/twitter.py", line 19, in <module>
except tweepy.errors.TweepError as e:
AttributeError: module 'tweepy.errors' has no attribute 'TweepError'
Any help will be really appreciated as I'm a newbie.
The text was updated successfully, but these errors were encountered:
In API v1.1, the response format of the Search API has been improved to return Tweet objects more similar to the objects you’ll find across the REST API and platform. However, perspectival attributes (fields that pertain to the perspective of the authenticating user) are not currently supported on this endpoint. 12
Hi everyone!
I've set a code that I've found on one tutorial. And after changing some parts because of being outdated I still get into a problem. The problem is that I check if a tweet is already liked but some how the conditional
if not tweet.favorited
doesn't work.Here the code:
And here the response I get on the terminal:
Any help will be really appreciated as I'm a newbie.
The text was updated successfully, but these errors were encountered: