Pastebin.com 帖子

发布于 2024-12-06 21:34:29 字数 311 浏览 1 评论 0原文

我正在尝试通过 Javascript 中的弹出窗口发布一个新的 Pastebin。我遇到的问题是它说“错误的 API 请求,无效的 api_option”

我正在使用的链接: http://pastebin.com/api/api_post.php?api_dev_key=&api_paste_name=T‌ ITLE&api_option=paste&api_paste_code=SOMETEXT

它表示将 api_option 作为粘贴。我尝试查找其他示例,但还没有运气。大家都遇到过这个问题吗?

I'm trying to post a new Pastebin through a popup window in Javascript. The issues I'm getting is it is saying "Bad API request, invalid api_option"

Link that I'm using:
http://pastebin.com/api/api_post.php?api_dev_key=<KEY>&api_paste_name=T‌​ITLE&api_option=paste&api_paste_code=SOMETEXT

It says to put api_option as paste. I've tried looking up other examples, but no luck yet. Has everyone ran into this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

找回味觉 2024-12-13 21:34:29

您是否有可能需要 POST 数据而不是 GET 数据?

此外,像这样将 API 密钥放在互联网上可能不是最好的主意。

Are you, by any chance, required to POST the data rather than GETting it?

Also, it might not be the best idea ever to put your API key on the internet like this.

柠檬心 2024-12-13 21:34:29

您如何向 Pastebin 提交此请求?是通过POST还是GET?我的最佳猜测是,您正在发送 GET 请求,而 API 需要 POST

How are you submitting this request to Pastebin? Is it via POST or GET? My best guess is that you're sending a GET request and the API requires a POST.

地狱即天堂 2024-12-13 21:34:29

试试这个:

   let api = {
      option: "paste",
      user_key: "XXXXXXXXXXXX",
      dev_key: 'XXXXXXXXXXXX',
      paste_name: "MyTitle",
      paste_format: "JSON",
      paste_private: 0,
      paste_code: ""
};

  let request = new XMLHttpRequest();
  request.open('POST', 'http://pastebin.com/api/api_post.php', true);
  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  data['test'] = 'Yeah PasteBin!';
  dataString = 'api_option='+api.option+'&api_user_key='+api.user_key+'&api_dev_key='+api.dev_key+
'&api_paste_name='+api.paste_name+'&api_paste_format='+api.paste_format+
'&api_paste_private='+api.paste_private+'&api_paste_code='+data;
request.onreadystatechange = function() {
    if (request.status == 200 && request.readyState == 4) {
        alert("URL to new pastebin file: " + request.responseText);
    }
}
  request.send(dataString);

代码的主要问题是将所有内容都放在请求 URL 中,如果它是 GET 请求,那没关系。 PasteBin 的 URL:api/api_post.php 需要 POST 请求(注意名称?),因此您必须在正文中发送它,就像我上面向您展示的那样。

Try this:

   let api = {
      option: "paste",
      user_key: "XXXXXXXXXXXX",
      dev_key: 'XXXXXXXXXXXX',
      paste_name: "MyTitle",
      paste_format: "JSON",
      paste_private: 0,
      paste_code: ""
};

  let request = new XMLHttpRequest();
  request.open('POST', 'http://pastebin.com/api/api_post.php', true);
  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  data['test'] = 'Yeah PasteBin!';
  dataString = 'api_option='+api.option+'&api_user_key='+api.user_key+'&api_dev_key='+api.dev_key+
'&api_paste_name='+api.paste_name+'&api_paste_format='+api.paste_format+
'&api_paste_private='+api.paste_private+'&api_paste_code='+data;
request.onreadystatechange = function() {
    if (request.status == 200 && request.readyState == 4) {
        alert("URL to new pastebin file: " + request.responseText);
    }
}
  request.send(dataString);

The main issue with your code is put everything in your request URL, what is fine if it is a GET request. The URL of PasteBin: api/api_post.php demands a POST request (notice the name?), so you have to send it in the body like I've shown you above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文