Created
December 5, 2012 21:16
-
-
Save julien51/4219570 to your computer and use it in GitHub Desktop.
An example of how to post content to a Tumblr blog with Lua. Usable in Webscript.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local tumblrName = "" -- Name of the Tumblr blog where the content will be posted | |
-- Extrat the data from the JSON notification and prepare it to be used as a Tumblr 'quote'. | |
local jsonContent = json.parse(request.body) | |
local quote = jsonContent.items[1].title | |
local sourceTitle = jsonContent.title | |
local sourceLink = jsonContent.standardLinks.self[1].href | |
-- Authenication against the Tumblr API. You will need to create an application and grab the OAuth access token. | |
-- Follow these instructions http://www.tumblr.com/oauth/apps and https://gist.github.com/4219558 | |
local AUTH = { oauth = { consumertoken='', consumersecret='', accesstoken='', tokensecret=''} } | |
-- Post the content to Tumblr | |
local res = http.request { | |
url = "http://api.tumblr.com/v2/blog/" .. tumblrName .. ".tumblr.com/post", | |
method = "POST", | |
auth = AUTH, | |
data = { | |
type = "quote", | |
quote = quote, | |
source = "<a href='"..sourceLink.."'>"..sourceTitle.."</a>" | |
} | |
} | |
-- Return it. Not so useful at this point | |
return res.statuscode, res.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment