使用searchtweets API,twitter api不断返回422错误

时间:2018-04-25 23:46:53

标签: python twitter http-status-code-422

我正在尝试使用https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes API检索历史数据,但我一直收到twitter 422错误。奇怪的是,在此代码之前,我有一个以前的代码,它完美地工作。但在此之后,旧代码无法正常工作

我已经按照文档,仔细检查了我是否拥有完整的存档访问权限,甚至重新生成了我的令牌和访问密钥。

这是我的python代码:

import json
import csv

from searchtweets import collect_results, load_credentials, gen_rule_payload

enterprise_search_args = load_credentials("twitter_keys.yaml", yaml_key = "search_tweets_api", env_overwrite = False)

from_date = "2016-06-01"
to_date = "2016-06-23"

with open('map_data/london_borough.csv', 'r', newline = "") as csvFile:
    boroughs = list(csv.reader(csvFile, delimiter = ','))
    for num, borough in enumerate(boroughs):
        if num:
            name = boroughs[0]
            box_coord = borough[5]
            if box_coord:
                box_coord = '['+box_coord.replace(',',' ')+']'
                print(box_coord)
                rule = gen_rule_payload("brexit", results_per_call = 100, from_date = from_date, to_date = to_date)
                rule = json.loads(rule)
                rule['bounding_box'] = box_coord
                rule = json.dumps(rule)
                print(rule)
                tweets = collect_results(rule, max_results = 500, result_stream_args = enterprise_search_args)
                with open('%s.csv'%(name), 'w', newline = "") as writeFile:
                    for tweet in tweets:
                        writeFile.write('%s, %s, %s\n'%(tweet.name, tweet.created_at_string, tweet.all_text))

我的yaml文件:

search_tweets_api:
account_type: premium
endpoint: https://api.twitter.com/1.1/tweets/search/fullarchive/StreamingTweets.json
consumer_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
consumer_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

运行上面的代码后,我在控制台上看到了这个:

Grabbing bearer token from OAUTH
[-0.105400 51.507354 -0.074673 51.521028]
{"query": "brexit", "maxResults": 100, "toDate": "201606230000", "fromDate": "201606010000", "bounding_box": "[-0.105400 51.507354 -0.074673 51.521028]"}
retrying request; current status code: 422
retrying request; current status code: 422

我的计算机时钟设置为UTC协调通用时间,我有四倍检查我的承载令牌并重新生成了几次,应用程序访问设置为读取,写入和访问直接消息但仍然不知道如何解决这个问题

有没有人知道解决方案或我可能出错的地方?任何帮助将不胜感激!

0 个答案:

没有答案