使用update_with_media将图像上传到Twitter - Lua

我想使用 update_with_media.json 将一张图片发布到 twitter 上。

以下是一个可以更新推文的工作代码,使用 statuses/update.json:

local url = "http://api.twitter.com/1/statuses/update.json"
local consumer_key = ""
local consumer_secret = ""
local token = ""
local token_secret = ""

local post_data =
    {
    oauth_consumer_key = consumer_key,
    oauth_nonce        = get_nonce(),
    oauth_signature_method = "HMAC-SHA1",
    oauth_token        = token,
    oauth_timestamp    = get_timestamp(),
    oauth_version      = '1.0',
    oauth_token_secret = token_secret

    }

post_data["status"] = "Hello Twitter!"
post_data = oAuthSign(url, "POST", post_data, consumer_secret)

r,c,h = http.request
   {
   url = url,
   method = "POST",
   headers =
         {
         ["Content-Type"] = "application/x-www-form-urlencoded",
         ["Content-Length"] = string.len(rawdata)
         },
   source = ltn12.source.string(post_data),
   sink = ltn12.sink.table(response)
   }

现在我该如何修改上面的代码来上传图片?

URL 将会是 "http://api.twitter.com/1/statuses/update\_with\_media.json",而 headers["Content-Type"] 将会是 "multipart/form-data"。

但是我在哪里以及如何指定要上传的图片呢?

点赞
用户1137788
用户1137788

将图片上传到 Twitter

我之前成功做到了这一点...

这篇帖子 by velluminteractive 提供了一个很好的用于处理 Twitter 的库。

诚然,这段代码是针对一个叫做 Corona SDK 的游戏引擎编写的。但是,只要将其中的 Corona 特定元素删除,其他人也可以轻松地使用它。

2012-10-21 11:18:33