{"id":13729251,"url":"https://github.com/michimani/gotwi","last_synced_at":"2025-04-12T23:29:17.119Z","repository":{"id":38015324,"uuid":"414286940","full_name":"michimani/gotwi","owner":"michimani","description":"A library for using the Twitter API v2 in the Go language. (It is still under development).","archived":false,"fork":false,"pushed_at":"2025-01-13T13:54:08.000Z","size":458,"stargazers_count":138,"open_issues_count":11,"forks_count":31,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-04T12:23:36.398Z","etag":null,"topics":["golang","twitter","twitter-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michimani.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG_DEV.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"michimani"}},"created_at":"2021-10-06T16:22:44.000Z","updated_at":"2025-04-02T16:29:04.000Z","dependencies_parsed_at":"2024-01-06T13:08:38.402Z","dependency_job_id":"0d0ce61d-b5ea-4de6-b7d6-4ebe475b6e8b","html_url":"https://github.com/michimani/gotwi","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fgotwi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fgotwi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fgotwi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michimani%2Fgotwi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michimani","download_url":"https://codeload.github.com/michimani/gotwi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248646615,"owners_count":21139039,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","twitter","twitter-api"],"created_at":"2024-08-03T02:00:57.457Z","updated_at":"2025-04-12T23:29:17.089Z","avatar_url":"https://github.com/michimani.png","language":"Go","funding_links":["https://github.com/sponsors/michimani"],"categories":["Libraries","Go"],"sub_categories":["Go"],"readme":"gotwi\n===\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/michimani/gotwi.svg)](https://pkg.go.dev/github.com/michimani/gotwi)\n[![Twitter API v2](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2)](https://developer.twitter.com/en/docs/twitter-api)\n[![codecov](https://codecov.io/gh/michimani/gotwi/branch/main/graph/badge.svg?token=NA873TE6RV)](https://codecov.io/gh/michimani/gotwi)\n\nThis is a library for using the Twitter API v2 in the Go language. (It is still under development).\n\n# Supported APIs\n\n[Twitter API Documentation | Docs | Twitter Developer Platform  ](https://developer.twitter.com/en/docs/twitter-api)\n\nProgress of supporting APIs:\n\n| Category | Sub Category | Endpoint |\n| --- | --- | --- |\n| Tweets | Tweet lookup | `GET /2/tweets` |\n|  |  | `GET /2/tweets/:id` |\n|  | Manage Tweet | `POST /2/tweets` |\n|  |  | `DELETE /2/tweets/:id` |\n|  | Timelines | `GET /2/users/:id/tweets` |\n|  |  | `GET /2/users/:id/mentions` |\n|  |  | `GET /2/users/:id/timelines/reverse_chronological` |\n|  | Search Tweets | `GET /2/tweets/search/recent` |\n|  |  | `GET /2/tweets/search/all` |\n|  | Tweet counts | `GET /2/tweets/counts/recent` |\n|  |  | `GET /2/tweets/counts/all` |\n|  | Filtered stream | `POST /2/tweets/search/stream/rules` |\n|  |  | `GET /2/tweets/search/stream/rules` |\n|  |  | `GET /2/tweets/search/stream` |\n|  | Volume streams | `GET /2/tweets/sample/stream` |\n|  | Retweets | `GET /2/users/:id/retweeted_by` |\n|  |  | `POST /2/users/:id/retweets` |\n|  |  | `DELETE /2/users/:id/retweets/:source_tweet_id` |\n|  | Likes | `GET /2/tweets/:id/liking_users` |\n|  |  | `GET /2/tweets/:id/liked_tweets` |\n|  |  | `POST /2/users/:id/likes` |\n|  |  | `DELETE /2/users/:id/likes/:tweet_id` |\n|  | Hide replies | `PUT /2/tweets/:id/hidden` |\n|  | Quote Tweets | `GET /2/tweets/:id/quote_tweets` |\n|  | Bookmarks | `GET /2/users/:id/bookmarks` |\n|  |  | `POST /2/users/:id/bookmarks` |\n|  |  | `DELETE /2/users/:id/bookmarks/:tweet_id` |\n| Users | User lookup | `GET /2/users` |\n|  |  | `GET /2/users/:id` |\n|  |  | `GET /2/users/by` |\n|  |  | `GET /2/users/by/username` |\n|  |  | `GET /2/users/by/me` |\n|  | Follows | `GET /2/users/:id/following` |\n|  |  | `GET /2/users/:id/followers` |\n|  |  | `POST /2/users/:id/following` |\n|  |  | `DELETE /2/users/:source_user_id/following/:target_user_id` |\n|  | Blocks | `GET /2/users/:id/blocking` |\n|  |  | `POST /2/users/:id/blocking` |\n|  |  | `DELETE /2/users/:source_user_id/blocking/:target_user_id` |\n|  | Mutes | `GET /2/users/:id/muting` |\n|  |  | `POST /2/users/:id/muting` |\n|  |  | `DELETE /2/users/:source_user_id/muting/:target_user_id` |\n| Lists | List lookup | `GET /2/lists/:id` |\n|  |  | `GET /2/users/:id/owned_lists` |\n|  | Manage Lists | `POST /2/lists` |\n|  |  | `DELETE /2/lists/:id` |\n|  |  | `PUT /2/lists/:id` |\n|  | List Tweets lookup | `GET /2/lists/:id/tweets` |\n|  | List members | `GET /2/users/:id/list_memberships` |\n|  |  | `GET /2/lists/:id/members` |\n|  |  | `POST /2/lists/:id/members` |\n|  |  | `DELETE /2/lists/:id/members/:user_id` |\n|  | List follows | `GET /2/lists/:id/followers` |\n|  |  | `GET /2/users/:id/followed_lists` |\n|  |  | `POST /2/users/:id/followed_lists` |\n|  |  | `DELETE /2/users/:id/followed_lists/:list_id` |\n|  | Pinned Lists | `GET /2/users/:id/pinned_lists` |\n|  |  | `POST /2/users/:id/pinned_lists` |\n|  |  | `DELETE /2/users/:id/pinned_lists/:list_id` |\n| Spaces | Spaces Lookup | `GET /2/spaces/:id` |\n|  |  | `GET /2/spaces` |\n|  |  | `GET /2/spaces/by/creator_ids` |\n|  |  | `GET /2/spaces/:id/buyers` |\n|  |  | `GET /2/spaces/:id/tweets` |\n|  | Search Spaces | `GET /2/spaces/search` |\n| Compliance | Batch compliance | `GET /2/compliance/jobs/:id` |\n|  |  | `GET /2/compliance/jobs` |\n|  |  | `POST /2/compliance/jobs` |\n\n\n# How to use\n\n## Prepare\n\nSet the API key and API key secret to environment variables.\n\n```bash\nexport GOTWI_API_KEY='your-api-key'\nexport GOTWI_API_KEY_SECRET='your-api-key-secret'\n```\n\n## Request with OAuth 1.0a User Context\n\nWith this authentication method, each operation will be performed as the authenticated Twitter account. For example, you can tweet as that account, or retrieve accounts that are blocked by that account.\n\n### Example: Get your own information.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/michimani/gotwi\"\n\t\"github.com/michimani/gotwi/fields\"\n\t\"github.com/michimani/gotwi/user/userlookup\"\n\t\"github.com/michimani/gotwi/user/userlookup/types\"\n)\n\nfunc main() {\n\tin := \u0026gotwi.NewClientInput{\n\t\tAuthenticationMethod: gotwi.AuthenMethodOAuth1UserContext,\n\t\tOAuthToken:           \"your-access-token\",\n\t\tOAuthTokenSecret:     \"your-access-token-secret\",\n\t}\n\n\tc, err := gotwi.NewClient(in)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tp := \u0026types.GetMeInput{\n\t\tExpansions: fields.ExpansionList{\n\t\t\tfields.ExpansionPinnedTweetID,\n\t\t},\n\t\tUserFields: fields.UserFieldList{\n\t\t\tfields.UserFieldCreatedAt,\n\t\t},\n\t\tTweetFields: fields.TweetFieldList{\n\t\t\tfields.TweetFieldCreatedAt,\n\t\t},\n\t}\n\n\tu, err := userlookup.GetMe(context.Background(), c, p)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Println(\"ID:          \", gotwi.StringValue(u.Data.ID))\n\tfmt.Println(\"Name:        \", gotwi.StringValue(u.Data.Name))\n\tfmt.Println(\"Username:    \", gotwi.StringValue(u.Data.Username))\n\tfmt.Println(\"CreatedAt:   \", u.Data.CreatedAt)\n\tif u.Includes.Tweets != nil {\n\t\tfor _, t := range u.Includes.Tweets {\n\t\t\tfmt.Println(\"PinnedTweet: \", gotwi.StringValue(t.Text))\n\t\t}\n\t}\n}\n```\n\n```\ngo run main.go\n```\n\nYou will get the output like following.\n\n```\nID:           581780917\nName:         michimani Lv.873\nUsername:     michimani210\nCreatedAt:    2012-05-16 12:07:04 +0000 UTC\nPinnedTweet:  OpenAI API の Function Calling を使って自然言語で AWS リソースを作成してみる\n```\n\n### Example: Tweet with poll.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/michimani/gotwi\"\n\t\"github.com/michimani/gotwi/tweet/managetweet\"\n\t\"github.com/michimani/gotwi/tweet/managetweet/types\"\n)\n\nfunc main() {\n\tin := \u0026gotwi.NewClientInput{\n\t\tAuthenticationMethod: gotwi.AuthenMethodOAuth1UserContext,\n\t\tOAuthToken:           \"your-access-token\",\n\t\tOAuthTokenSecret:     \"your-access-token-secret\",\n\t}\n\n\tc, err := gotwi.NewClient(in)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tp := \u0026types.CreateInput{\n\t\tText: gotwi.String(\"This is a test tweet with poll.\"),\n\t\tPoll: \u0026types.CreateInputPoll{\n\t\t\tDurationMinutes: gotwi.Int(5),\n\t\t\tOptions: []string{\n\t\t\t\t\"Cyan\",\n\t\t\t\t\"Magenta\",\n\t\t\t\t\"Yellow\",\n\t\t\t\t\"Key plate\",\n\t\t\t},\n\t\t},\n\t}\n\n\tres, err := managetweet.Create(context.Background(), c, p)\n\tif err != nil {\n\t\tfmt.Println(err.Error())\n\t\treturn\n\t}\n\n\tfmt.Printf(\"[%s] %s\\n\", gotwi.StringValue(res.Data.ID), gotwi.StringValue(res.Data.Text))\n}\n```\n\n```\ngo run main.go\n```\n\nYou will get the output like following.\n\n```\n[1462813519607263236] This is a test tweet with poll.\n```\n\n## Request with OAuth 2.0 Bearer Token\n\nThis authentication method allows only read-only access to public information.\n\n### Example: Get a user by user name.\n\n⚠ This example only works with Twitter API v2 Basic or Pro plan. see details: [Developers Portal](https://developer.twitter.com/en/portal/products)\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/michimani/gotwi\"\n\t\"github.com/michimani/gotwi/fields\"\n\t\"github.com/michimani/gotwi/user/userlookup\"\n\t\"github.com/michimani/gotwi/user/userlookup/types\"\n)\n\nfunc main() {\n\tc, err := gotwi.NewClient(\u0026gotwi.NewClientInput{\n\t\tAuthenticationMethod: gotwi.AuthenMethodOAuth2BearerToken,\n\t})\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tp := \u0026types.GetByUsernameInput{\n\t\tUsername: \"michimani210\",\n\t\tExpansions: fields.ExpansionList{\n\t\t\tfields.ExpansionPinnedTweetID,\n\t\t},\n\t\tUserFields: fields.UserFieldList{\n\t\t\tfields.UserFieldCreatedAt,\n\t\t},\n\t\tTweetFields: fields.TweetFieldList{\n\t\t\tfields.TweetFieldCreatedAt,\n\t\t},\n\t}\n\n\tu, err := userlookup.GetByUsername(context.Background(), c, p)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Println(\"ID:          \", gotwi.StringValue(u.Data.ID))\n\tfmt.Println(\"Name:        \", gotwi.StringValue(u.Data.Name))\n\tfmt.Println(\"Username:    \", gotwi.StringValue(u.Data.Username))\n\tfmt.Println(\"CreatedAt:   \", u.Data.CreatedAt)\n\tif u.Includes.Tweets != nil {\n\t\tfor _, t := range u.Includes.Tweets {\n\t\t\tfmt.Println(\"PinnedTweet: \", gotwi.StringValue(t.Text))\n\t\t}\n\t}\n}\n```\n\n```\ngo run main.go\n```\n\nYou will get the output like following.\n\n```\nID:           581780917\nName:         michimani Lv.861\nUsername:     michimani210\nCreatedAt:    2012-05-16 12:07:04 +0000 UTC\nPinnedTweet:  真偽をハッキリしたい西城秀樹「ブーリアン、ブーリアン」\n```\n\n## Request with OAuth 2.0 Authorization Code with PKCE\n\nIf you already have a pre-generated access token (e.g. OAuth 2.0 Authorization Code with PKCE), you can use `NewClientWithAccessToken()` function to generate a Gotwi client.\n\n```go\nin := \u0026gotwi.NewClientWithAccessTokenInput{\n\tAccessToken: \"your-access-token\",\n}\n\nc, err := gotwi.NewClientWithAccessToken(in)\nif err != nil {\n\t// error handling\n}\n```\n\nSee below for information on which authentication methods are available for which endpoints.\n\n[Twitter API v2 authentication mapping | Docs | Twitter Developer Platform  ](https://developer.twitter.com/en/docs/authentication/guides/v2-authentication-mapping)\n\n## Error handling\n\nEach function that calls the Twitter API (e.g. `retweet.ListUsers()`) may return an error for some reason.\nIf the error is caused by the Twitter API returning a status other than 2XX, you can check the details by doing the following.\n\n```go\nres, err := retweet.ListUsers(context.Background(), c, p)\nif err != nil {\n\tfmt.Println(err)\n\n\t// more error information\n\tge := err.(*gotwi.GotwiError)\n\tif ge.OnAPI {\n\t\tfmt.Println(ge.Title)\n\t\tfmt.Println(ge.Detail)\n\t\tfmt.Println(ge.Type)\n\t\tfmt.Println(ge.Status)\n\t\tfmt.Println(ge.StatusCode)\n\n\t\tfor _, ae := range ge.APIErrors {\n\t\t\tfmt.Println(ae.Message)\n\t\t\tfmt.Println(ae.Label)\n\t\t\tfmt.Println(ae.Parameters)\n\t\t\tfmt.Println(ae.Code)\n\t\t\tfmt.Println(ae.Code.Detail())\n\t\t}\n\n\t\tif ge.RateLimitInfo != nil {\n\t\t\tfmt.Println(ge.RateLimitInfo.Limit)\n\t\t\tfmt.Println(ge.RateLimitInfo.Remaining)\n\t\t\tfmt.Println(ge.RateLimitInfo.ResetAt)\n\t\t}\n\t}\n}\n```\n\n\n\n## More examples\n\nSee [_examples](https://github.com/michimani/gotwi/tree/main/_examples) directory.\n\n# Licence\n\n[MIT](https://github.com/michimani/gotwi/blob/main/LICENCE)\n\n# Author\n\n[michimani210](https://twitter.com/michimani210)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichimani%2Fgotwi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichimani%2Fgotwi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichimani%2Fgotwi/lists"}