repositorypackage
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)