geduldig / TwitterAPI

Minimal python wrapper for Twitter's REST and Streaming APIs
938 stars 263 forks source link

TwitterPager not returning anything? #134

Closed tonyalas closed 4 years ago

tonyalas commented 4 years ago

I am trying use the Premium Search API to loop through a list of words to search based on the user who is authenticating themselves (for example, search: @tonyalas3 "car") but when I use TwitterPager, nothing seems to return or print.

    api = TwitterAPI(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token_key=access_token, access_token_secret=access_token_secret)
    for word in wordsList:
        r = TwitterPager(api, 'tweets/search/30day/:search30', {'query': screen_name+'%20%22'+ word +'%22'})
        # loop through the tweets retrieved
        for item in r.get_iterator():
            # print the tweet username and text to terminal
            print(item["user"]["screen_name"])
            print(item["text"])

            # save and store tweet info
            tweet_username = item["user"]["screen_name"] # save the username
            tweet_text = item["text"] # save the text from the tweet
            tweet_id = item["id_str"]   # save the tweet id (used for linking and deleting purposes)

            # add the above items to their corresponding lists
            tweets.append(tweet_text) # add username to the corresponding list
            tweets_ids.append(tweet_id) # add the tweet id to the corresponding list
            tweets_usernames.append(tweet_username) # add the tweet's author (username) to the corresponding list

Even if I do something simple and less dynamic like:

    badword = "feel"
    r = TwitterPager(api, 'tweets/search/30day/:search30', {'query': 'tonyalas3%20%22'+ badword +'%22'})
    for tweet in r.get_iterator():
        print("test")

Nothing prints to the terminal, but after checking my subscriptions usage, it still counts as a request. (I also know for a fact that I have tweeted something with the word "feel" in it in the past 30 days). The weird thing is that using the regular 'search/tweets' request with the api (standard search) returns the tweet containing the word "feel" within the last week, but the premium api does not want to work for some reason. If you know of this happening to anyone else and can help, I would greatly appreciate it, thank you.

geduldig commented 4 years ago

Instead of {'query': 'tonyalas3%20%22'+ badword +'%22'} try {'query': 'tonyalas3 "badword"'}

Does this fix your problem?