Lua - 上传到Pastebin

时间:2015-09-23 20:29:33

标签: api upload lua roblox pastebin

请注意,这是Roblox的lua版本。 我想将一个表上传到Pastebin。这就是我对Pastebin的看法。

$(document).ready(function() {
    $("td:first-child").each(function() {
        if ($(this).text() === "Confirmed") {
            $(this).parent().addClass("green");
        }
        else {
            $(this).parent().addClass("red");
        }
    });
});

这不起作用,我似乎无法弄清楚原因。

编辑: 我也试过这个并且它没有用。

h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript is a table formatted like {{x,y,z}, {x,y,z}, {x,y,z}, etc.}
h:PostAsync('http://pastebin.com/api/api_post.php','&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)

编辑: 我也尝试了这个并且它没有工作:

h = game:GetService'HttpService'
api_params = {
    ["api_dev_key"] = "CensoredDevKey",
    ["api_option"] = "paste",
    ["api_paste_code"] = ImgScript
}
api_params = h:JSONEncode(api_params)
h:PostAsync('http://www.pastebin.com/api/api_post.php', api_params)

2 个答案:

答案 0 :(得分:3)

尝试以下方法:

h = game:GetService'HttpService'
pasteData = h:UrlEncode( h:JSONEncode(ImgScript) )
h:PostAsync(
    'http://pastebin.com/api/api_post.php',
    'api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. pasteData,
    2
)

发送的数据的最后一个参数2 specifies thatApplication/Url-Encoded

我认为这应该可以解决问题。如果没有,请告知此处。

PS:你在哪里收到这个POST请求的结果?

答案 1 :(得分:0)

所以我已经完成了代码,但遗憾的是,Roblox将PostAsync大小限制为256字节,因此任何大于此的上传都将是GZIPed(高达1024kb),而Pastebin不知道该怎么做用。

无论如何,我在这里发布了代码: http://www.roblox.com/Pastebin-Upload-item?id=302297532

是:

--Created by GShocked. PM me if you have questions!

h = game:GetService'HttpService'
api_dev_key = '' --Your Pastebin developer key goes here. Log in first, and then you can find it at pastebin.com/api
api_paste_code = '' --The content of your new paste
api_paste_private = '1' --0 public; 1 unlisted; 2 private
api_paste_name = '' --Name your new paste
api_paste_expire_date = 'N' --N for never expire, 10M for 10 minutes, etc.
api_paste_format = 'lua' --The syntax highlighting
api_user_key = '' --This is generated using the login info
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = '' --Your Pastebin username goes here
password = '' --Your Pastebin password goes here

api_user_key = h:PostAsync(
    'http://pastebin.com/api/api_login.php',
    'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
    2
)
print(api_user_key) --DON'T DELETE THIS! IT IS ESSENTIAL FOR THE USER KEY TO BE GENERATED!
h:PostAsync(
    'http://pastebin.com/api/api_post.php',
    'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code,
    2
)