twitterquerygo

package module
v0.0.0-...-e501259 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

twittersearchgo

This project extends kurrik's twittergo Twitter client with search orientated features.

The goal of this project is to provide an efficient way of working with timelines by searching for tweets by using max_id and since_id query parameters. In case of a RateLimitError, the reset of the timestamp will be returned - it's the duty of the caller to wait the required time.

Build Status Go Report Card GoDoc Widget

Installing

Run

go get github.com/MihaiBogdanEugen/twittersearchgo

Include in your source:

import "github.com/MihaiBogdanEugen/twittersearchgo"

Using dep:

dep ensure -add github.com/MihaiBogdanEugen/twittersearchgo

Godoc

See http://godoc.org/github.com/MihaiBogdanEugen/twittersearchgo

Configuration

One can configure a SearchTwitterClient by providing at least:

  • the Twitter API Consumer Key and
  • the Twitter API Consumer Secret.

Thus, the client will use application authentication. For user authentication, the additional following parameters must be provided:

  • the Twitter API Access Token and
  • the Twitter API Access Token Secret

Apart of these, there are the following optional parameters:

Name Required Description Default Value
language optional Restricts tweets to the given language, given by an ISO 639-1 code. Language detection is best-effort. en
max_id optional Returns results with an ID less than (that is, older than) or equal to the specified ID. -
result_type optional Specifies what type of search results you would prefer to receive. Valid values include: mixed - Include both popular and real time results in the response; recent - return only the most recent results in the response; popular - return only the most popular results in the response. mixed
since_id optional Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available. -

Credits

All credits go to the original author, this project is a mere extension.

References

Documentation

Overview

Package twitterquerygo implements a search-optimized Twitter client library in Go.

Index

Constants

View Source
const BatchSize = 100

BatchSize Query for tweets in batches of this size

Variables

This section is empty.

Functions

This section is empty.

Types

type ISearchClient

type ISearchClient interface {
	// SetSinceID sets the since_id query parameter
	SetSinceID(sinceID uint64)

	// SetMaxID sets the max_id query parameter
	SetMaxID(maxID uint64)

	// SetResultType sets the result_type query parameter
	SetResultType(resultType string)

	// SetLanguage sets the lang query parameter
	SetLanguage(language string)

	// SetLogger sets the logger
	SetLogger(logger *logrus.Logger)

	// Search searches tweets given a search parameter 'q' till either there are no more results or the rate limit is exceeded
	Search(query string) (*SearchTweetsResponse, error)
}

ISearchClient defines the behaviour of a search-optimized Twitter client.

type SearchTweetsResponse

type SearchTweetsResponse struct {
	Tweets             []twittergo.Tweet
	HasRateLimit       bool
	RateLimit          uint32
	RateLimitRemaining uint32
	RateLimitReset     time.Time
}

SearchTweetsResponse implements the response of a search query, containing tweets and the timestamp when the rate limit resets

type SearchTwitterClient

type SearchTwitterClient struct {
	TwitterClient twittergo.Client
	SinceID       uint64
	MaxID         uint64
	ResultType    string
	Language      string
	// contains filtered or unexported fields
}

SearchTwitterClient implements a search-optimized Twitter client.

func NewClientUsingAppAuth

func NewClientUsingAppAuth(consumerKey string, consumerSecret string) *SearchTwitterClient

NewClientUsingAppAuth creates a new SearchClient using application authentication, with a rate limited to 450 requests per 15 minutes

func NewClientUsingUserAuth

func NewClientUsingUserAuth(consumerKey string, consumerSecret string, accessToken string, accessTokenSecret string) *SearchTwitterClient

NewClientUsingUserAuth creates a new SearchClient using user authentication, with a rate limited to 180 requests per 15 minutes

func (*SearchTwitterClient) Search

Search searches tweets given a search parameter 'q' till either there are no more results or the rate limit is exceeded

func (*SearchTwitterClient) SetLanguage

func (c *SearchTwitterClient) SetLanguage(language string)

SetLanguage sets the lang query parameter

func (*SearchTwitterClient) SetLogger

func (c *SearchTwitterClient) SetLogger(logger *logrus.Logger)

SetLogger sets the logger

func (*SearchTwitterClient) SetMaxID

func (c *SearchTwitterClient) SetMaxID(maxID uint64)

SetMaxID sets the max_id query parameter

func (*SearchTwitterClient) SetResultType

func (c *SearchTwitterClient) SetResultType(resultType string)

SetResultType sets the result_type query parameter

func (*SearchTwitterClient) SetSinceID

func (c *SearchTwitterClient) SetSinceID(sinceID uint64)

SetSinceID sets the since_id query parameter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL