modulepackage
0.0.0-20201204234051-ecec2e804999
Repository: https://github.com/kylebevans/twitapi.git
Documentation: pkg.go.dev
# README
Go API client for twitapi
API Reference — v2
Quick example to get tweets from the last 7 days that match a search query
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/antihax/optional"
"github.com/kylebevans/twitapi"
)
func main() {
ctx := context.WithValue(context.Background(), twitapi.ContextAccessToken, os.Getenv("TWITTER_BEARER_TOKEN"))
cfg := twitapi.NewConfiguration()
apiClient := twitapi.NewAPIClient(cfg)
var searchOpts *twitapi.TweetsRecentSearchOpts
searchOpts = new(twitapi.TweetsRecentSearchOpts)
var tweets twitapi.TweetSearchResponse
var nextToken optional.String
var err error
// API is paginated, so print pages of recent tweets in the last week
// that mention "tasty sandwich" until they are all done
for ok := true; ok; ok = (tweets.Meta.NextToken != "") {
tweets, _, err = apiClient.SearchApi.TweetsRecentSearch(ctx, "\"tasty sandwich\"", searchOpts)
if err != nil {
panic(err)
}
for _, v := range tweets.Data {
fmt.Printf("%v\n\u001b[31m--------\n\u001b[0m", v.Text)
}
nextToken = optional.NewString(tweets.Meta.NextToken)
searchOpts.NextToken = nextToken
time.Sleep(2 * time.Second) // Twitter API is rate limited to 450 requests per 15 min
}
}
Overview
This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.
- API version: 2.2
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.GoClientCodegen For more information, please visit https://developer.twitter.com/
Installation
Install the following dependencies:
go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional
Put the package under your project folder and add the following in import:
import "./twitapi"
Documentation for API Endpoints
All URIs are relative to https://api.twitter.com
Class | Method | HTTP request | Description |
---|---|---|---|
GeneralApi | GetOpenApiSpec | Get /2/openapi.json | Returns the open api spec document. |
RulesApi | AddOrDeleteRules | Post /2/tweets/search/stream/rules | Add or delete rules from a user's active rule set. |
RulesApi | GetRules | Get /2/tweets/search/stream/rules | Returns rules from a user's active rule set. |
SearchApi | TweetsFullarchiveSearch | Get /2/tweets/search/all | Returns Tweets that match a search query. |
SearchApi | TweetsRecentSearch | Get /2/tweets/search/recent | Returns Tweets from the last 7 days that match a search query. |
TweetsApi | AddOrDeleteRules | Post /2/tweets/search/stream/rules | Add or delete rules from a user's active rule set. |
TweetsApi | FindTweetById | Get /2/tweets/{id} | Returns hydrated Tweet objects |
TweetsApi | FindTweetsById | Get /2/tweets | Returns hydrated Tweet objects |
TweetsApi | GetRules | Get /2/tweets/search/stream/rules | Returns rules from a user's active rule set. |
TweetsApi | HideReplyById | Put /2/tweets/{id}/hidden | Hides or unhides a reply to an owned conversation. |
TweetsApi | SampleStream | Get /2/tweets/sample/stream | Streams a deterministic 1% of public tweets. |
TweetsApi | SearchStream | Get /2/tweets/search/stream | Streams tweets matching a user's active rule set. |
TweetsApi | TweetsFullarchiveSearch | Get /2/tweets/search/all | Returns Tweets that match a search query. |
TweetsApi | TweetsRecentSearch | Get /2/tweets/search/recent | Returns Tweets from the last 7 days that match a search query. |
UsersApi | FindUserById | Get /2/users/{id} | Return details for the specified users |
UsersApi | FindUserByUsername | Get /2/users/by/username/{username} | Return details for the specified users |
UsersApi | FindUsersById | Get /2/users | Return details for the specified users |
UsersApi | FindUsersByUsername | Get /2/users/by | Return details for the specified users |
Documentation For Models
- AddOrDeleteRulesRequest
- AddOrDeleteRulesResponse
- AddRulesRequest
- AddRulesResponse
- AnimatedGif
- AnimatedGifAllOf
- CashtagEntity
- CashtagFields
- ClientDisconnectedProblem
- ClientDisconnectedProblemAllOf
- ClientForbiddenProblem
- ClientForbiddenProblemAllOf
- CommonMediaFields
- ConnectionExceptionProblem
- ConnectionExceptionProblemAllOf
- ContextAnnotation
- ContextAnnotationDomainFields
- ContextAnnotationEntityFields
- DeleteRulesRequest
- DeleteRulesResponse
- DisallowedResourceProblem
- DisallowedResourceProblemAllOf
- DuplicateRuleProblem
- DuplicateRuleProblemAllOf
- EntityIndices
- Error
- Expansions
- FieldUnauthorizedProblem
- FieldUnauthorizedProblemAllOf
- FilteredStreamingTweet
- FilteredStreamingTweetOneOf
- FilteredStreamingTweetOneOfMatchingRules
- FullTextEntities
- GenericProblem
- GenericProblemAllOf
- Geo
- HashtagEntity
- HashtagFields
- InlineObject
- InlineResponse200
- InlineResponse2001
- InlineResponse2001Meta
- InlineResponse2002
- InlineResponse200Data
- InvalidRequestProblem
- InvalidRequestProblemAllOf
- InvalidRequestProblemAllOfErrors
- InvalidRuleProblem
- InvalidRuleProblemAllOf
- Media
- MentionEntity
- MentionFields
- OperationalDisconnectProblem
- OperationalDisconnectProblemAllOf
- Photo
- PhotoAllOf
- Place
- PlaceType
- Point
- Poll
- PollOption
- Problem
- ProblemFields
- ResourceNotFoundProblem
- ResourceNotFoundProblemAllOf
- ResourceUnauthorizedProblem
- ResourceUnauthorizedProblemAllOf
- Rule
- RuleNoId
- RulesCapProblem
- RulesCapProblemAllOf
- RulesRequestSummary
- RulesRequestSummaryOneOf
- RulesRequestSummaryOneOf1
- RulesResponseMetadata
- SingleTweetLookupResponse
- SingleUserLookupResponse
- StreamingTweet
- StreamingTweetOneOf
- Tweet
- TweetAttachments
- TweetGeo
- TweetLookupResponse
- TweetLookupResponseMeta
- TweetNonPublicMetrics
- TweetOrganicMetrics
- TweetPromotedMetrics
- TweetPublicMetrics
- TweetReferencedTweets
- TweetSearchResponse
- TweetWithheld
- UnsupportedAuthenticationProblem
- UnsupportedAuthenticationProblemAllOf
- UrlEntity
- UrlFields
- UrlImage
- UsageCapExceededProblem
- UsageCapExceededProblemAllOf
- User
- UserEntities
- UserEntitiesUrl
- UserLookupResponse
- UserPublicMetrics
- UserWithheld
- Video
- VideoAllOf
- VideoAllOfNonPublicMetrics
- VideoAllOfOrganicMetrics
- VideoAllOfPromotedMetrics
- VideoAllOfPublicMetrics
Documentation For Authorization
BearerToken
- Type: HTTP basic authentication
Example
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
UserToken
- Type: HTTP basic authentication
Example
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
Author
# Functions
CacheExpires helper function to determine remaining time before repeating a request.
NewAPIClient creates a new API client.
NewAPIResponse returns a new APIResonse object.
NewAPIResponseWithError returns a new APIResponse object with the provided error message.
NewConfiguration returns a new Configuration object.
# Constants
List of PlaceType.
List of PlaceType.
List of PlaceType.
List of ReplySettings.
List of ReplySettings.
List of ReplySettings.
List of PlaceType.
List of ReplySettings.
List of PlaceType.
List of PlaceType.
# Variables
ContextAccessToken takes a string oauth2 access token as authentication for the request.
ContextAPIKey takes an APIKey as authentication for the request.
ContextBasicAuth takes BasicAuth as authentication for the request.
ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
# Structs
AddOrDeleteRulesOpts Optional parameters for the method 'AddOrDeleteRules'.
AddOrDeleteRulesRequest struct for AddOrDeleteRulesRequest.
AddOrDeleteRulesResponse struct for AddOrDeleteRulesResponse.
AddRulesRequest struct for AddRulesRequest.
AddRulesResponse struct for AddRulesResponse.
AnimatedGif struct for AnimatedGif.
AnimatedGifAllOf struct for AnimatedGifAllOf.
APIClient manages communication with the Early Access API v2.2 In most cases there should be only one, shared, APIClient.
APIKey provides API key based authentication to a request passed via context using ContextAPIKey.
APIResponse stores the API response returned by the server.
BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth.
CashtagEntity struct for CashtagEntity.
CashtagFields Represent the portion of text recognized as a Cashtag, and its start and end position within the text.
ClientDisconnectedProblem Your client has gone away.
ClientDisconnectedProblemAllOf struct for ClientDisconnectedProblemAllOf.
ClientForbiddenProblem A problem that indicates your client is forbidden from making this request.
ClientForbiddenProblemAllOf struct for ClientForbiddenProblemAllOf.
CommonMediaFields struct for CommonMediaFields.
Configuration stores the configuration of the API client.
ConnectionExceptionProblem A problem that indicates something is wrong with the connection.
ConnectionExceptionProblemAllOf struct for ConnectionExceptionProblemAllOf.
ContextAnnotation Annotation inferred from the tweet text.
ContextAnnotationDomainFields Represents the data for the context annotation domain.
ContextAnnotationEntityFields Represents the data for the context annotation entity.
DeleteRulesRequest struct for DeleteRulesRequest.
DeleteRulesResponse struct for DeleteRulesResponse.
DisallowedResourceProblem A problem that indicates that the resource requested violates the precepts of this API.
DisallowedResourceProblemAllOf struct for DisallowedResourceProblemAllOf.
DuplicateRuleProblem The rule you have submitted is a duplicate.
DuplicateRuleProblemAllOf struct for DuplicateRuleProblemAllOf.
EntityIndices Represent a boundary range (start and end index) for a recognized entity (for example a hashtag or a mention).
Error struct for Error.
Expansions struct for Expansions.
FieldUnauthorizedProblem A problem that indicates that you are not allowed to see a particular field on a Tweet, User, etc.
FieldUnauthorizedProblemAllOf struct for FieldUnauthorizedProblemAllOf.
FilteredStreamingTweet A tweet or error that can be returned by the streaming tweet API.
FilteredStreamingTweetOneOf The values returned with a successful streamed tweet.
FilteredStreamingTweetOneOfMatchingRules struct for FilteredStreamingTweetOneOfMatchingRules.
FindTweetByIdOpts Optional parameters for the method 'FindTweetById'.
FindTweetsByIdOpts Optional parameters for the method 'FindTweetsById'.
FindUserByIdOpts Optional parameters for the method 'FindUserById'.
FindUserByUsernameOpts Optional parameters for the method 'FindUserByUsername'.
FindUsersByIdOpts Optional parameters for the method 'FindUsersById'.
FindUsersByUsernameOpts Optional parameters for the method 'FindUsersByUsername'.
FullTextEntities struct for FullTextEntities.
GenericOpenAPIError Provides access to the body, error and model on returned errors.
GenericProblem A generic problem with no additional information beyond that provided by the HTTP status code.
GenericProblemAllOf struct for GenericProblemAllOf.
Geo struct for Geo.
GetRulesOpts Optional parameters for the method 'GetRules'.
HashtagEntity struct for HashtagEntity.
HashtagFields Represent the portion of text recognized as a Hashtag, and its start and end position within the text.
HideReplyByIdOpts Optional parameters for the method 'HideReplyById'.
InlineObject struct for InlineObject.
InlineResponse200 struct for InlineResponse200.
InlineResponse2001 struct for InlineResponse2001.
InlineResponse2001Meta struct for InlineResponse2001Meta.
InlineResponse2002 struct for InlineResponse2002.
InlineResponse200Data struct for InlineResponse200Data.
InvalidRequestProblem A problem that indicates this request is invalid.
InvalidRequestProblemAllOf struct for InvalidRequestProblemAllOf.
InvalidRequestProblemAllOfErrors struct for InvalidRequestProblemAllOfErrors.
InvalidRuleProblem The rule you have submitted is invalid.
InvalidRuleProblemAllOf struct for InvalidRuleProblemAllOf.
Media struct for Media.
MentionEntity struct for MentionEntity.
MentionFields Represent the portion of text recognized as a User mention, and its start and end position within the text.
OperationalDisconnectProblem You have been disconnected for operational reasons.
OperationalDisconnectProblemAllOf struct for OperationalDisconnectProblemAllOf.
Photo struct for Photo.
PhotoAllOf struct for PhotoAllOf.
Place struct for Place.
Point A [GeoJson Point](https://tools.ietf.org/html/rfc7946#section-3.1.2) geometry object.
Poll Represent a Poll attached to a Tweet.
PollOption Describes a choice in a Poll object.
Problem An HTTP Problem Details object, as defined in IETF RFC 7807 (https://tools.ietf.org/html/rfc7807).
ProblemFields struct for ProblemFields.
ResourceNotFoundProblem A problem that indicates that a given Tweet, User, etc.
ResourceNotFoundProblemAllOf struct for ResourceNotFoundProblemAllOf.
ResourceUnauthorizedProblem A problem that indicates you are not allowed to see a particular Tweet, User, etc.
ResourceUnauthorizedProblemAllOf struct for ResourceUnauthorizedProblemAllOf.
Rule struct for Rule.
RuleDeleteIds struct for RuleDeleteIds.
RuleNoId struct for RuleNoId.
RulesCapProblem You have exceeded the maximum number of rules.
RulesCapProblemAllOf struct for RulesCapProblemAllOf.
RulesRequestSummary struct for RulesRequestSummary.
RulesRequestSummaryOneOf struct for RulesRequestSummaryOneOf.
RulesRequestSummaryOneOf1 struct for RulesRequestSummaryOneOf1.
RulesResponseMetadata struct for RulesResponseMetadata.
SampleStreamOpts Optional parameters for the method 'SampleStream'.
SearchStreamOpts Optional parameters for the method 'SearchStream'.
ServerConfiguration stores the information about a server.
ServerVariable stores the information about a server variable.
SingleTweetLookupResponse struct for SingleTweetLookupResponse.
SingleUserLookupResponse struct for SingleUserLookupResponse.
StreamingTweet A tweet or error that can be returned by the streaming tweet API.
StreamingTweetOneOf struct for StreamingTweetOneOf.
Tweet struct for Tweet.
TweetAttachments Specifies the type of attachments (if any) present in this Tweet.
TweetGeo The location tagged on the Tweet, if the user provided one.
TweetLookupResponse struct for TweetLookupResponse.
TweetLookupResponseMeta struct for TweetLookupResponseMeta.
TweetNonPublicMetrics Nonpublic engagement metrics for the Tweet at the time of the request.
TweetOrganicMetrics Organic nonpublic engagement metrics for the Tweet at the time of the request.
TweetPromotedMetrics Promoted nonpublic engagement metrics for the Tweet at the time of the request.
TweetPublicMetrics Engagement metrics for the Tweet at the time of the request.
TweetReferencedTweets struct for TweetReferencedTweets.
TweetSearchResponse struct for TweetSearchResponse.
TweetsFullarchiveSearchOpts Optional parameters for the method 'TweetsFullarchiveSearch'.
TweetsRecentSearchOpts Optional parameters for the method 'TweetsRecentSearch'.
TweetWithheld Indicates withholding details for [withheld content](https://help.twitter.com/en/rules-and-policies/tweet-withheld-by-country).
UnsupportedAuthenticationProblem A problem that indicates that the authentication used is not supported.
UnsupportedAuthenticationProblemAllOf struct for UnsupportedAuthenticationProblemAllOf.
UrlEntity Represent the portion of text recognized as a URL, and its start and end position within the text.
UrlFields Represent the portion of text recognized as a URL.
UrlImage Represent the information for the URL image.
UsageCapExceededProblem A problem that indicates that a usage cap has been exceeded.
UsageCapExceededProblemAllOf struct for UsageCapExceededProblemAllOf.
User The Twitter User object.
UserEntities A list of metadata found in the user's profile description.
UserEntitiesUrl Expanded details for the URL specified in the user's profile, with start and end indices.
UserLookupResponse struct for UserLookupResponse.
UserPublicMetrics A list of metrics for this user.
UserWithheld Indicates withholding details for [withheld content](https://help.twitter.com/en/rules-and-policies/tweet-withheld-by-country).
Video struct for Video.
VideoAllOf struct for VideoAllOf.
VideoAllOfNonPublicMetrics Nonpublic engagement metrics for the Media at the time of the request.
VideoAllOfOrganicMetrics Organic nonpublic engagement metrics for the Media at the time of the request.
VideoAllOfPromotedMetrics Promoted nonpublic engagement metrics for the Media at the time of the request.
VideoAllOfPublicMetrics Engagement metrics for the Media at the time of the request.
# Type aliases
GeneralApiService GeneralApi service.
PlaceType the model 'PlaceType'.
ReplySettings Shows who can reply a Tweet.
RulesApiService RulesApi service.
SearchApiService SearchApi service.
TweetsApiService TweetsApi service.
UsersApiService UsersApi service.