{"id":13895748,"url":"https://github.com/leafo/lua-twitter","last_synced_at":"2025-10-24T07:16:13.400Z","repository":{"id":54372370,"uuid":"65580738","full_name":"leafo/lua-twitter","owner":"leafo","description":"A Lua twitter library that works with OpenResty or LuaSocket","archived":false,"fork":false,"pushed_at":"2021-02-08T23:34:07.000Z","size":66,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T17:39:48.804Z","etag":null,"topics":["lua","luasocket","moonscript","openresty","twitter","twitter-api"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leafo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-12T20:10:33.000Z","updated_at":"2023-06-05T04:39:35.000Z","dependencies_parsed_at":"2022-08-13T13:40:49.496Z","dependency_job_id":null,"html_url":"https://github.com/leafo/lua-twitter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-twitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-twitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-twitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-twitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafo","download_url":"https://codeload.github.com/leafo/lua-twitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253817589,"owners_count":21969007,"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":["lua","luasocket","moonscript","openresty","twitter","twitter-api"],"created_at":"2024-08-06T18:02:26.658Z","updated_at":"2025-10-24T07:16:08.347Z","avatar_url":"https://github.com/leafo.png","language":"Lua","readme":"# twitter\n\n![test](https://github.com/leafo/lua-twitter/workflows/test/badge.svg)\n\n\nA Lua library for working with the Twitter API.\n\nThis library is designed to work with either LuaSocket or OpenResty's\nco-sockets via Lapis. If `ngx` is not in scope then the library will fall back\nto LuaSocket for network.\n\n`luasec` is required when using LuaSocket for `https` communication.\n\n# Install\n\n```bash\nluarocks install https://luarocks.org/manifests/leafo/twitter-dev-1.rockspec\n```\n\n# Reference\n\nBefore getting started you'll need a *consumer key* and *consumer secret*. To\nget those you'll need to create an app at \u003chttps://apps.twitter.com\u003e.\n\n## Application only authentication\n\nThere are a few ways to authenticate with the Twitter API. The easiest way is\nto request without a user context using the cosnumer keys:\n\n```lua\nlocal Twitter = require(\"twitter\").Twitter\n\nlocal twitter = Twitter({\n  consumer_key = \"XXXXXXX\",\n  consumer_secret = \"ABCABCABACABACACB\"\n})\n```\n\nThis will allow you to run read-only API calls for public information.\n\nIf you want to do things like post statuses and upload images using the account\nthat owns the consumer keys then you can generate a access token and secret\nfrom \u003chttps://apps.twitter.com\u003e and use them like so:\n\n```lua\nlocal Twitter = require(\"twitter\").Twitter\n\nlocal twitter = Twitter({\n  consumer_key = \"XXXXXXX\",\n  consumer_secret = \"ABCABCABACABACACB\",\n  access_token = \"abcdefg-123456\",\n  access_token_secret = \"awkeftSECretgwKWARKW\"\n})\n```\n\n## 3-Legged OAuth\n\nIf you want to add \"Sign in with Twitter\" then you can use this approach.\n\nCreate a new client with your consumer key and secret:\n\n```lua\nlocal Twitter = require(\"twitter\").Twitter\n\nlocal twitter = Twitter({\n  consumer_key = \"XXXXXXX\",\n  consumer_secret = \"ABCABCABACABACACB\"\n})\n```\n\nGenerate the URL to redirect the user to. (You should redirect their browser to this URL)\n\n```lua\nlocal url = twitter:sign_in_with_twitter_url()\n```\n\nAfter the user completes the sign in at the URL, they'll be redirect to the\ncallback URL on your website that you provided on the Twitter developers page.\n\nThe callback URL also some two query parameters attached to it: `oauth_token`\nand `oauth_verifier`. You can use this information to create an access token\nfor the user:\n\n```lua\nlocal result = twitter:verify_sign_in_token(oauth_token, oauth_verifier)\n```\n\nThe result is an object that looks approximately like this:\n\n```json\n{\n  \"oauth_token\": \"XXXXXXXX-XXXXXXXXXXXX\",\n  \"oauth_token_secret\": \"XXXXXXXXXXXXXX\",\n  \"user_id\": \"123434\",\n  \"screen_name\": \"itchio\",\n  \"x_auth_expires\": \"0\"\n}\n```\n\nYou can now use the `oauth_token` and `oauth_token_secret` to create a new\nTwitter client to make requests on their behalf. Use the same `consumer_key`\nand `consumer_secret` as before:\n\n\n```lua\nlocal user_client = Twitter({\n  access_token = result.oauth_token,\n  access_token_secret = result.oauth_token_secret,\n\n  consumer_key = \"XXXXXXX\",\n  consumer_secret = \"ABCABCABACABACACB\"\n})\n\nuser_client:post_status({ status = \"Hello world!\" })\n```\n\n# Methods\n\nAll of the following methods are available on an instance of the `Twitter`\nclass provided by the `twitter` module.\n\n### `get_user(opts={})`\n\nhttps://dev.twitter.com/rest/reference/get/users/show\n\nGet information about a user\n\n```lua\nlocal user = twitter:get_user({\n  screen_name = \"moonscript\"\n})\n```\n\n### `get_user_timeline(opts={})`\n\nhttps://dev.twitter.com/rest/reference/get/statuses/user_timeline\n\nGet a page of tweets for a user's timeline.\n\n```lua\nlocal tweets = twitter:get_user_timeline({\n  screen_name = \"moonscript\",\n  include_rts = \"0\",\n})\n```\n\n### `user_timeline_each_tweet(opts={})`\n\nReturns an iterator to get every Tweet available in the API. Calls\n`get_user_timeline` repeatedly, updating `max_id` accordingly.\n\nWill set `count` to 200 if not specified.\n\n```lua\nfor tweet in twitter:user_timeline_each_tweet({ screen_name = \"moonscript\" }) do\n  print(tweet.text)\nend\n```\n\n### `post_status(opts={})`\n\nhttps://dev.twitter.com/rest/reference/post/statuses/update\n\nCreates a new tweet for the user.\n\nThis requires authentication with a user context. You can get an access token\nfor your own account from \u003chttps://apps.twitter.com/\u003e.\n\n```lua\nlocal user = assert(twitter:post_status({\n  status = \"Hello, this my tweet\"\n}))\n```\n### `post_media_upload(opts={})`\n\nUploads a image or video to Twitter, returns the media object. You can attach\nthe media object to a status update by including the id returned by this call\nin the `post_status` method.\n\n```lua\nlocal media = assert(twitter:post_media_upload({\n  filename = \"mything.gif\"\n}))\n\nassert(twitter:post_status {\n  status = \"feeling itchy pt. 3\",\n  media_ids = media.media_id_string\n})\n```\n\n#### Uploading from URL\n\nYou can also upload an image directly from URL by passing in the URL of the\nimage to `url`.\n\n```lua\nlocal media = assert(twitter:post_media_upload({\n  url: \"http://leafo.net/hi.png\"\n}))\n```\n\n# Contact\n\nAuthor: Leaf Corcoran (leafo) ([@moonscript](http://twitter.com/moonscript))  \nEmail: leafot@gmail.com  \nHomepage: \u003chttp://leafo.net\u003e  \nLicense: MIT  \n\n","funding_links":[],"categories":["Lua"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Flua-twitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafo%2Flua-twitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Flua-twitter/lists"}