行上的Twitter API searchtweets模块错误-result_stream_args = premium_search_args

时间:2019-02-04 18:51:51

标签: python api twitter

.twitter_keys.yaml文件中似乎没有密钥错误,并且有效的凭证也存在。错误出现在第result_stream_args-premium_search_args

twitter_search.py​​文件

from searchtweets import ResultStream, gen_rule_payload, load_credentials, collect_results

import requests

premium_search_args = load_credentials("~/.twitter_keys.yaml",
                                       yaml_key="search_tweets_premium",
                                       env_overwrite=False)


rule = gen_rule_payload("superbowl", results_per_call=100) # testing with a sandbox account
print(rule)

from searchtweets import collect_results

tweets = collect_results(rule, 
                         max_results=100, 
                         result_stream_args=premium_search_args)


# print(tweets.all_text)

[print(tweet.all_text, end='\n\n') for tweet in tweets[0:10]];

出现以下错误:

  

C:\ Users \ hp \ Dev \ Twitter \ twitter_search \ src> python twitter_search.py​​

     

从OAUTH {“ query”:“ superbowl”,“ maxResults”抓取承载令牌:   100}追溯(最近一次通话结束):文件“ twitter_search.py​​”,   第17行       result_stream_args = premium_search_args)文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ site-packages \ searchtweets \ result_stream.py”,   第308行,在collect_results中       返回列表(rs.stream())文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ site-packages \ searchtweets \ result_stream.py”,   流中的208行       self.execute_request()文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ site-packages \ searchtweets \ result_stream.py”,   第263行,在execute_request中       resp = json.loads(resp.content.decode(resp.encoding))文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ json__init __。py”,第354行,   在负载中       在解码中返回_default_decoder.decode文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ json \ decoder.py”,行339       obj,end = self.raw_decode(s,idx = _w(s,0).end())文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ json \ decoder.py”,第357行,在   raw_decode       从None引发JSONDecodeError(“期望值”,s,err.value)json.decoder.JSONDecodeError:期望值:第1行第1列(字符   0)

1 个答案:

答案 0 :(得分:1)

原来是由于.twitter_keys.yaml文件中的错误而端点不正确。在这种情况下,端点应该是

endpoint: https://api.twitter.com/1.1/tweets/search/30day/development.json

30天可以更改为full_archive等。