Twitter

class quotek::datasource::twitter

Twitter is a class that allows to fetch twitter content from the regular API.

Inherits from quotek::datasource::datasource

Public Functions

twitter(std::string consumer_key, std::string consumer_secret, std::string token, std::string token_secret)

twitter class constructor. To get all the constructor parameters, just go to https://apps.twitter.com/, create a new app and go to “Keys and Access Tokens”.

Parameters
  • consumer_key -

    Twitter app consumer key.

  • consumer_secret -

    Twitter app consumer secret.

  • token -

    Twitter app token.

  • token_secret -

    Twitter app token secret.

~twitter()

twitter class destructor

std::vector<quotek::data::news> fetch(std::string screen_name, int nb_tweets)

fetches the last tweets of given user.

Return
a vector of quotek news objects.
Parameters
  • screen_name -

    The name of account to fetch tweets for.

  • nb_tweets -

    The number of tweets to fetch (sorted by descending date)

std::vector<quotek::data::news> search(std::string term, int nb_tweets)

searches the tweets matching the term provided as argument.

Return
a vector of quotek news objects matching the search.
Parameters
  • term -

    term to search in the global tweets feed.

  • nb_tweets -

    The number of found tweets to retrieve.

std::vector<quotek::data::news> search(std::string term, int nb_tweets, std::string result_type, std::string lang)

searches the tweets matching the term provided as argument. This method refines the usual search() method by adding 2 extra parameters: result_type and language.

Return
a vector of quotek news objects matching the search.
Parameters
  • term -

    term to search in the global tweets feed.

  • nb_tweets -

    The number of found tweets to retrieve.

  • result_type -

    Type of the search result, can be either “popular”, “recent” or “mixed”.

  • language -

    of the tweets, eg for english only tweets put lang = “en”.

Example

You will find below a sample source code about how to use the Quotek Twitter client to fetch the 40 most recent tweets containing the word “DOWJONES”. */

#include <quotek/quotek.hpp>
#include <quotek/datasources/twitter.hpp>
#include <iostream>

using namespace quotek::datasource;
using namespace quotek::data;

int main(int argc, char** argv) {

  //We declare a new Twitter client.
  twitter tw1("TWITTER-CONSUMER-KEY",
              "TWITTER-CONSUMER-SECRET",
              "TWITTER-TOKEN",
              "TWITTER-TOKEN-SECRET");

  //we fetch the 40 most recent tweets matching "DOWJONES"
  std::vector<news> nvect = tw1.search("DOWJONES",40,"recent","en");

  //Then we iterate through them to display their content on stdout.
  for(int i=0;i<nvect.size();i++) {
    std::cout << nvect[i].content << std::endl;
  }

}