【问题标题】:Twitter REST API v1.1 - searching by date?Twitter REST API v1.1 - 按日期搜索?
【发布时间】:2013-06-12 13:49:10
【问题描述】:

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

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

【问题讨论】:

    标签: python twitter python-module


    【解决方案1】:

    简短回答,是的

    例如:

    #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 的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 2013-07-24
      • 2013-08-19
      • 2023-03-30
      • 2013-08-15
      相关资源
      最近更新 更多