0

有没有办法使用 Twitter 的 API 1.1 来搜索特定日期或上周具有特定查询的所有帖子?

是否应该有任何符合 API 的 python 模块能够做到这一点(我一直在使用 twython),或者是否有任何特定的模块可以为这项任务推荐?

4

1 回答 1

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()

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

于 2014-02-05T15:34:24.933 回答