Lua
Lua
Twitter OAuth -- Tweet to Your Own Account
See more HTTP Examples
Demonstrates how to send a tweet (status update) to your own Twitter account using pre-known credentials, which includes:
- Consumer Key
- Consumer Secret
- Access Token
- Token Secret
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
http.oauth1 = true
http.oauth_verifier = ""
http.oauth_consumer_key = "my-consumer-key"
http.oauth_consumer_secret = "my-consumer-secret"
http.oauth_token = "my-access-token"
http.oauth_token_secret = "my-token-secret"
-- Send the same status update as shown in this example:
-- https://dev.twitter.com/docs/api/1.1/post/statuses/update
-- IMPORTANT: Make sure this app has read/write access.
-- Otherwise it cannot post an update (i.e. tweet) to the Twitter account.
local req = chilkat.HttpRequest.new()
req:add_param("status", "Maybe he'll finally find his keys. #peterfalk")
req.http_verb = "POST"
req.content_type = "application/x-www-form-urlencoded"
local resp = chilkat.HttpResponse.new()
local success = http:http_req("https://api.twitter.com/1.1/statuses/update.json", req, resp)
if not success then
print(http.last_error_text)
return
end
if resp.status_code == 200 then
-- Display the JSON response.
print(resp.body_str)
else
print(http.last_error_text)
end