Driving Twitter with just LUA

2 replies [Last post]
brett
Offline
Providence, United States
Joined: 9 Jan 2010

I was thinking about google calender and how the library is deprectated and that got me thinking... "is it possible to drive twitter with just LUA as it has to OAUTH and then pound a REST API just like googlecal does?"

So I compiled up a few lua helper modules and stamped out a simple LUA program that would talk to twitter.

local OAuth = require "OAuth"
oauth_token = "9xxxgIqm"
oauth_token_secret = "DptRmDxxxxxOXHv3eTNc"
consumer_secret="6iaSFRxxxxcFNv7lQyoA"
consumer_key="hmGxxxxxnw"

client = OAuth.new(consumer_key, consumer_secret, {
        RequestToken = "https://api.twitter.com/oauth/request_token",
        AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"},
        AccessToken = "https://api.twitter.com/oauth/access_token"
}, {
        OAuthToken = oauth_token,
        OAuthTokenSecret = oauth_token_secret
})

-- the mandatory "Hello World" example...
local response_code, response_headers, response_status_line, response_body =
client:PerformRequest("GET", "https://api.twitter.com/1.1/statuses/user_timeline.json", {screen_name = "dbzoo"})
print("response_code", response_code)
print("response_status_line", response_status_line)
for k,v in pairs(response_headers) do print(k,v) end
print("response_body", response_body)

Pretty simple for starters.... more to come.

derek
Offline
Glasgow, United Kingdom
Joined: 26 Oct 2009
Sweet stuff

Two points.

1. Where do we find the various tokens/keys

2. Would a similar 'Lua script based' approach work for Google Calendar (appreciate that this would involve a fair bit of effort)? 

Cheers,
Derek.

brett
Offline
Providence, United States
Joined: 9 Jan 2010
The OAUTH tokens are in

The OAUTH tokens are in /etc/xap.d/xap-twitter.ini at least for twitter they are.  For google calender you have traditionally been able to use basic auth, but I believe google has turned this off forcing you to use OAUTH which is why suddenly googlecal has broken.   I've yet to confirm that but I'm pretty sure this is the case.
That and the fact that Nov 2014 the v2 google api is going to be deprecated giving more reason to not even bother with trying to patch up the existing libgcal framework which is v2 based and XML.  v3 is JSON based.

I'm not sure how much work there is to write a LUA based googlecal but this is where I'm heading.
Getting OAUTH working in LUA is the hard battle fought which is why I used twitter as the test case.
Now its just a matter of driving the the REST API which should be pretty simple from LUA.

Brett

Hardware Info