Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

favorited not working #1909

Closed
venturaEffect opened this issue Jun 7, 2022 · 1 comment
Closed

favorited not working #1909

venturaEffect opened this issue Jun 7, 2022 · 1 comment
Labels
API This is regarding Twitter's API Duplicate This is a duplicate

Comments

@venturaEffect
Copy link

venturaEffect commented Jun 7, 2022

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:

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.

@Harmon758
Copy link
Member

Harmon758 commented Jun 11, 2022

Duplicate of #1233

You'll want to regenerate your credentials now, if you haven't already.

Also, note, like the error says, TweepError doesn't exist anymore.

From Tweepy's documentation on API.search_tweets:

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

Footnotes

  1. https://web.archive.org/web/20170829051949/https://dev.twitter.com/rest/reference/get/search/tweets

  2. https://twittercommunity.com/t/favorited-reports-as-false-even-if-status-is-already-favorited-by-the-user/11145

@Harmon758 Harmon758 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2022
@Harmon758 Harmon758 added Duplicate This is a duplicate API This is regarding Twitter's API labels Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API This is regarding Twitter's API Duplicate This is a duplicate
Projects
None yet
Development

No branches or pull requests

2 participants