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 state in search is always false #1233

Closed
lg188 opened this issue Jun 27, 2019 · 5 comments
Closed

Favorited state in search is always false #1233

lg188 opened this issue Jun 27, 2019 · 5 comments
Labels
API This is regarding Twitter's API Documentation This is regarding the library's documentation

Comments

@lg188
Copy link

lg188 commented Jun 27, 2019

I've been trying to use the status.favorited variable of a status retrieved by api.search but it was always false. When trying to favorite this tweet it gave me exceptions with a message that that tweet was already favorited. After some help from the discord, I've discovered that this is fault on the twitter API itself [1]. My suggestion is to internally cross reference with a user's favorites to mitigate this.

As a developer, this was not a fun experience and I want to prevent this from happening to others.

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

@Harmon758
Copy link
Member

Adding additional indirect API requests to a discrete method that matches a specific endpoint is not something that Tweepy should do. Tweepy serves as an interface to the API and the limitations of it aren't necessarily in the purview of or part of the responsibility of the library to mitigate. Specifically, modifying the data returned from an API request would be bad practice, as it is not something a user would normally expect from any of the methods. It would also be a breaking change and be susceptible to breakage from any attempts by Twitter itself to rectify the limitation.

However, I do agree that this is an obscure limitation that's not properly documented at all by Twitter.
I myself was unaware of it until you brought it to my attention. But after confirming it wasn't an issue with your code and double checking the documentation for the method, all it took was a quick forum search to find the relevant thread. Nevertheless, since this now seems to be left out by Twitter in the actual documentation, I think it would be suitable to include it in Tweepy's documentation of the method.

Feel free to PR the addition of a note about it in the documentation for API.search.
I would recommend linking to that thread as a source in that note.

@Harmon758 Harmon758 added API This is regarding Twitter's API Documentation This is regarding the library's documentation labels Jun 27, 2019
@Freyja-Folkvangr
Copy link

@lg188 I've found a workaround for this.
for each status, overwrite that status by the same status, but from a different endpoint.

status = api.get_status(status.id)

@thekillgfx
Copy link

I've just encounter the same problem, searching on google I've found out that search/tweets endpoint of Twitter API v1 does not support “perspectival attributes” (ie. values which depend on the authenticating user). Anyone knows if they fixed anything pushing the version2?

Here is the thread where I've found the problem explained https://twittercommunity.com/t/favorited-reports-as-false-even-if-status-is-already-favorited-by-the-user/11145/, they also say that the best workaround seems to be the one posted by @Freyja-Folkvangr.

@Harmon758
Copy link
Member

Please don't necro-bump old closed issues.

@thekillgfx That is the same thread that is linked in this issue and that was added to the documentation with 1ab1519, the commit that closed this issue. The relevant Twitter API documentation you're referencing was also added to Tweepy's documentation in that commit.

As for Twitter API v2 support, see #1472.

@paulwababu
Copy link

Here is my fix for tweepy4.1, hope this helps someone

for tweet in tweepy.Cursor(api.search_tweets, search).items(maxNumberOfTweets):
    try:
        print(tweet.text)
        #for each status, overwrite that status by the same status, but from a different endpoint.
        status = api.get_status(tweet.id, tweet_mode='extended')
        if status.retweeted == False and status.favorited == False:
            print(colored('Found tweet by @' + tweet.user.screen_name, 'cyan'))
            tweet.favorite()
            print(colored('Liked tweet', 'green'))
            tweet.retweet()
            print(colored('Retweeted tweet', 'green'))
            api.update_status('@' + tweet.user.screen_name + ' ' + 'I like and retweet trending hashtags in Kenya every 95-115 seconds.'+'\n'+search, in_reply_to_status_id=tweet.id)
        #Updating count for each successfull retweet
        count = count + 1
        print(colored('Retweet #' + str(count) + ' published successfully.', 'green'))

        #Random wait time
        timeToWait = random.randint(95, 115)
        print("Waiting for "+ str(timeToWait) + " seconds")
        for remaining in range(timeToWait, -1, -1):
            sys.stdout.write("\r")
            sys.stdout.write("{:2d} seconds remaining.".format(remaining))
            sys.stdout.flush()
            time.sleep(1)
        sys.stdout.write("\rOnwards to next tweet!\n")

    except tweepy.TweepError as e:
        print('Error: ' + e.args[0][0]['message'])
        continue
    except StopIteration:
        break

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 Documentation This is regarding the library's documentation
Projects
None yet
Development

No branches or pull requests

5 participants