简体   繁体   English

twitter api的twython搜索字符串限制:结果丢失

[英]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 我已经使用本教程创建了一个Twitter机器人

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. 我不知道我是否超过了Twitter搜索API的限制(我发现了几个不同的数字),或者OR的字符串OR OR OR混乱还是太长。

any advice for python and the twitter api is welcome. 欢迎提供有关python和twitter api的任何建议。 many thanks 非常感谢

EDIT: A UTF-8, URL-encoded search query of 500 characters maximum, including operators. 编辑:UTF-8,URL编码的最大500个字符的搜索查询,包括运算符。 Queries may additionally be limited by complexity. 查询可能另外受到复杂性的限制。

even with the OR and spaces i am still not over the limit. 即使使用OR和空格,我仍然没有超出限制。

i think i solved the problem by using %22 instead of the quotation marks. 我认为我通过使用%22而不是引号解决了问题。 many thanks 非常感谢

good_words = ["%2this is one phrase%22", "%22this is another%22"] good_words = [“%2this是一个短语%22”,“%22this是另一个%22”]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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