Twitter REST API v1.1 - 按日期搜索?

时间:2013-06-12 13:49:11

标签: python twitter python-module

有没有办法使用Twitter的API 1.1在特定日期或最后一周搜索特定查询的所有帖子?

任何符合API的python模块是否能够执行此操作(我一直在使用twython),或者是否有人可以推荐用于此任务的特定模块?

1 个答案:

答案 0 :(得分:0)

简短回答,

例如:

#Import the required modules
from twython import Twython
import json
import csv

#Set the path for the output file
path = r'C:\Users\etc\file.txt'

#Setting the OAuth
Consumer_Key = 'XXX';
Consumer_Secret = 'XXX';
Access_Token = 'XXX';
Access_Token_Secret = 'XXX';

#Connection established with Twitter API v1.1
twitter = Twython(Consumer_Key, Consumer_Secret, Access_Token, Access_Token_Secret);

#Twitter is queried
response = twitter.search(q='%40annoys_parrot', since = '2014-02-04', until = '2014-02-05');

#Results are printed
print(json.dumps(response, sort_keys = True, indent = 2))

#Results are saved to txt file
file = open(path, 'w')
file.write((json.dumps(response, sort_keys = True, indent = 2))) 
file.close()

然后,您只需要解析结果。您可以找到有关此here的更多信息。