JAVASCRIPT 17
PostPastebinPost Guest on 20th September 2020 08:11:25 PM
  1. function postPastebinPost() {
  2. var options, url, apiKey, payload, response;
  3. apiKey = <api key goes here>;
  4. payload = 'Hello World';
  5. options = {
  6. 'method' : 'post',
  7. 'payload' : payload
  8. };
  9. url = 'https://pastebin.com/api/api_post.php'
  10. + '?api_dev_key=' + apiKey
  11. + '&api_option=paste'
  12. + '&api_paste_code=' + encodeURIComponent(payload);
  13. response = UrlFetchApp.fetch(url, options);
  14. Logger.log(response);
  15. }
  16. I run this and my log reads Bad API request, invalid api_option. I've searched for solutions but I have not found any.
  17. Documentation:
  18. • Pastebin.com API
  19. • Google Apps Script's UrlFetchApp Class
  20. The parameters should be passed in the payload of the POST request.
  21. function postPastebinPost() {
  22. var apiKey = 'YOUR KEY GOES HERE';
  23. var text = 'text';
  24. var payload = {
  25. api_dev_key: apiKey,
  26. api_option: 'paste',
  27. api_paste_code: text
  28. };
  29. var options = {
  30. method : 'POST',
  31. payload: payload
  32. };
  33. var url = 'https://pastebin.com/api/api_post.php';
  34. var response = UrlFetchApp.fetch(url, options);
  35. Logger.log(response.getContentText());
  36. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.