简体   繁体   中英

twython search string limit with twitter api : results missing

Hello I am super new to coding, still in the phase, copy paste, learn, change some variables, run, cross fingers, bang fist or raise fist...etc.

I have created a twitter bot using this tutorial

my code is as follows

import time
from twython import Twython, TwythonError

app_key = "xxxx"
app_secret = "xxxx"
oauth_token = "xxxx"
oauth_token_secret = "xxxx"


naughty_words = [" -RT"]

good_words = ["search phrase", "another search phrase", "yet another", "one more", "search phrase two", "TFW search phrase"]


filter = " OR ".join(good_words)

blacklist = " -".join(naughty_words)

keywords = filter + blacklist

twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)

search_results = twitter.search(q=keywords, count=100)
try:
for tweet in search_results["statuses"]:
    try:
        twitter.retweet(id = tweet["id_str"])
        except TwythonError as e:
        print e
except TwythonError as e:
print e

time.sleep(300)

so when i run the code it sometimes get results and it retweets them, but if i run the code with just two of the search terms it finds more and retweets them.

i dont know if i am over the twitter search api limit (which i found several different numbers for) or the string of OR OR OR OR is messed up or too long.

any advice for python and the twitter api is welcome. many thanks

EDIT: A UTF-8, URL-encoded search query of 500 characters maximum, including operators. Queries may additionally be limited by complexity.

even with the OR and spaces i am still not over the limit.

i think i solved the problem by using %22 instead of the quotation marks. many thanks

good_words = ["%2this is one phrase%22", "%22this is another%22"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM