【问题标题】:how to get all tweets past and present with particular # tag or @ tag如何使用特定的#标签或@标签获取过去和现在的所有推文
【发布时间】:2019-05-13 18:19:40
【问题描述】:

我正在尝试为一个组织申请,该组织需要获取所有过去和现在的推文,并带有一些特定的标签,如#airtel、@airtel 等,我应该如何通过推文,我能够获取现在带有以下网址的推文:“https://api.twitter.com/1.1/search/tweets.json?q=%23airtel

谢谢

【问题讨论】:

    标签: twitter


    【解决方案1】:

    您最多可以使用 twitter rest api 获得 100 条推文,请参阅以下twitter documentation。你能做的最好的就是使用计数参数https://api.twitter.com/1.1/search/tweets.json?q=%23airtel&count=100

    【讨论】:

    • 但是我怎样才能获得超过 100 条推文呢?
    • 你可以查看上面的ans。
    【解决方案2】:

    在 Google 上进行各种搜索后,我发现了一些用于获取推文的有用库,例如​​:

    TwitterSearch [https://github.com/ckoepp/TwitterSearch],你会找到我的推特资料@https://twitter.com/twittersearch

    Tweepy [https://github.com/tweepy/tweepy],您可以在http://www.tweepy.org/找到更多信息

    我已经实现了两者。 Tweepy 实现如下:

    import tweepy
    import json
    
    consumer_key = "get"
    consumer_secret = "From"
    access_token = "Twitter"
    access_token_secret = "site"
    # Authenticate twitter Api
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    
    api = tweepy.API(auth)
    #made a cursor
    c = tweepy.Cursor(api.search, q='%23Coursera')
    c.pages(15) # you can change it make get tweets
    
    #Lets save the selected part of the tweets inot json
    tweetJson = []
    for tweet in c.items():
        if tweet.lang == 'en':
            createdAt = str(tweet.created_at)
            authorCreatedAt = str(tweet.author.created_at)
            tweetJson.append(
              {'tweetText':tweet.text,
    
              'tweetCreatedAt':createdAt,
              'authorName': tweet.author.name,
              })
    #dump the data into json format
    print json.dumps(tweetJson)
    

    如果有人有问题,请告诉我,我会为此提供 git repo。

    谢谢 克里希纳

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      相关资源
      最近更新 更多