1

我正在尝试使用 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”

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

4

1 回答 1

1

Ok I got this working some time back.. This post by velluminteractive provides a good library to deal with twitter.

Admittedly the code is for a game engine called Corona SDK. But it shouldn't be too hard for others to use by removing Corona-specific elements from it.

于 2012-10-21T11:18:33.447 回答