Documentation ¶
Overview ¶
Package twitter implements a client for the Twitter API v2. This package is in development and is not yet ready for production use.
Usage outline ¶
The general structure of an API call is to first construct a query, then invoke that query with a context on a client:
cli := twitter.NewClient(&jape.Client{ Authorize: jape.BearerTokenAuthorizer(token), }) ctx := context.Background() rsp, err := users.LookupByName("jack", nil).Invoke(ctx, cli) if err != nil { log.Fatalf("Request failed: %v", err) } else if len(rsp.Users) == 0 { log.Fatal("No matches") } process(rsp.Users)
Packages ¶
Package "types" contains the type and constant definitions for the API.
Queries to look up tweets by ID or username, to search recent tweets, and to search or sample streams of tweets are defined in package "tweets".
Queries to look up users by ID or user name are defined in package "users".
Queries to read or update search rules are defined in package "rules".
Queries to create, edit, delete, and show the contents of lists are defined in package "lists".
Index ¶
Constants ¶
const ( // BaseURL is the default base URL for the production Twitter API. // This is the default base URL if one is not given in the client. BaseURL = "https://api.twitter.com" // NextTokenParam is the name of the query parameter used to send a page // token to the service. NextTokenParam = "pagination_token" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callback ¶
A Callback function is invoked for each reply received in a stream. If the callback reports a non-nil error, the stream is terminated. If the error is anything other than ErrStopStreaming, it is reported to the caller.
type Client ¶
A Client serves as a client for the Twitter API v2.
func NewClient ¶
NewClient returns a new client for the Twitter API. If cli == nil, default client options are used targeting the production API at BaseURL.
func (*Client) Call ¶
Call issues the specified API request and returns the decoded reply. Errors from Call have concrete type *jape.Error.
type Pagination ¶
type Pagination struct { ResultCount int `json:"result_count"` NextToken string `json:"next_token"` }
Pagination records metadata about pagination of results.
type RateLimit ¶
type RateLimit struct { Ceiling int // rate limit ceiling for this endpoint Remaining int // requests remaining in the current window Reset time.Time // time of next window reset }
RateLimit records metadata about API rate limits reported by the server.
type Reply ¶
type Reply struct { // The root reply object from a successful query. Data json.RawMessage `json:"data,omitempty"` // For expansions that generate attachments, a map of attachment type to // JSON arrays of attachment objects. Includes map[string]json.RawMessage `json:"includes,omitempty"` // Server metadata reported with search replies. Meta json.RawMessage `json:"meta,omitempty"` // Error details reported with lookup or search replies. Errors []*types.ErrorDetail `json:"errors,omitempty"` // Rate limit metadata reported by the server. If the server did not return // these data, this field will be nil. RateLimit *RateLimit `json:"-"` }
A Reply is a wrapper for the reply object returned by successful calls to the Twitter API v2.
func (*Reply) IncludedMedia ¶
IncludedMedia decodes any media objects in the includes of r. It returns nil without error if there are no media inclusions.
func (*Reply) IncludedPlaces ¶
IncludedPlaces decodes any place objects in the includes of r. It returns nil without error if there are no place inclusions.
func (*Reply) IncludedPolls ¶
IncludedPolls decodes any poll objects in the includes of r. It returns nil without error if there are no poll inclusions.
func (*Reply) IncludedTweets ¶
IncludedTweets decodes any tweet objects in the includes of r. It returns nil without error if there are no tweet inclusions.
Directories ¶
Path | Synopsis |
---|---|
Package edit implements editing operations on tweets and tweet metadata.
|
Package edit implements editing operations on tweets and tweet metadata. |
internal
|
|
ocall
Package ocall carries some shared utility code for calling the Twitter API v1.1.
|
Package ocall carries some shared utility code for calling the Twitter API v1.1. |
otest
Package otest carries some shared setup code for unit tests.
|
Package otest carries some shared setup code for unit tests. |
Package jape implements a client for a JSON-based HTTP API.
|
Package jape implements a client for a JSON-based HTTP API. |
auth
Package auth supports OAuth 1.0a request signing.
|
Package auth supports OAuth 1.0a request signing. |
Package lists supports queries for lists.
|
Package lists supports queries for lists. |
Package olists implements queries that operate on lists using the Twitter API v1.1.
|
Package olists implements queries that operate on lists using the Twitter API v1.1. |
Package ostatus implements queries that operate on statuses (tweets) using the Twitter API v1.1.
|
Package ostatus implements queries that operate on statuses (tweets) using the Twitter API v1.1. |
Package query defines a structured builder for search query strings.
|
Package query defines a structured builder for search query strings. |
Package rules implements queries for reading and modifying the rules used by streaming search queries.
|
Package rules implements queries for reading and modifying the rules used by streaming search queries. |
Package tokens defines queries to obtain and authorize access tokens for the Twitter API.
|
Package tokens defines queries to obtain and authorize access tokens for the Twitter API. |
Package tweets supports queries for tweet lookup and search.
|
Package tweets supports queries for tweet lookup and search. |
Package types defines types for the Twitter API v2 object model.
|
Package types defines types for the Twitter API v2 object model. |
mkenum
Program mkenum constructs type enumerations for the optional fields that may be requested in Twitter API v2.
|
Program mkenum constructs type enumerations for the optional fields that may be requested in Twitter API v2. |
Package users supports queries for user lookup.
|
Package users supports queries for user lookup. |