2

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.

Tearzz
  • 321
  • 1
  • 4
  • 14

1 Answers1

3

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.

wp78de
  • 18,207
  • 7
  • 43
  • 71
  • I would like to do all of this is one script by only using libraries like Sha1, JSON, and LuaSocket. I don't want functionality to any other part of the Twitter API. – Tearzz Nov 25 '18 at 15:04
  • 1
    I'm experiencing with [lua-cURL](https://github.com/Lua-cURL/Lua-cURLv3) to do HTTP requests. Because luasocket isn't able to do the actual tls standard. lua-cURL has some build in options for authentication (for instance Basic and Digest). Bearer needs libcurl 7.61.0. So you could write a function to handle the OAuth 2.0 with several requests. – csaar Nov 26 '18 at 07:57