Search code examples
twitteroauthluatwitter-oauthluasocket

How to send a POST request with OAUTH in Lua


So I want to tweet on Twitter by sending a POST request to the Twitter API.

I have not found a simple way to do this (unless I use a wrapper), and I'm not too experienced with Lua. This is Twitter's own example using curl:

$ curl --request POST 
--url 'https://api.twitter.com/1.1/statuses/update.json?
status=Test%20tweet%20using%20the%20POST%20statuses%2Fupdate%20endpoint' 
--header 'authorization: OAuth oauth_consumer_key="YOUR_CONSUMER_KEY",
oauth_nonce="AUTO_GENERATED_NONCE", oauth_signature="AUTO_GENERATED_SIGNATURE",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="AUTO_GENERATED_TIMESTAMP",
oauth_token="USERS_ACCESS_TOKEN", oauth_version="1.0"' 
--header 'content-type: application/json'

But from some wrappers I've seen, it seems that you can use:

consumer_key
consumer_secret
access_token
access_token_secret

I just want a simple way of tweeting without being able to have all of the other API functionality that the Twitter API has. So no wrapper or anything. Just a simple script, but I can't seem to figure it out. Any help is greatly appreciated.


Solution

  • Use a specialized Lua library for Twitter, e.g. https://github.com/leafo/lua-twitter

    luarocks install https://luarocks.org/manifests/leafo/twitter-dev-1.rockspec
    

    or a more general Lua library for OAuth, e.g. https://github.com/ignacio/LuaOAuth and do the rest yourself.