From 7deee78cc89ab93e3b7895949b43f3a59d99df07 Mon Sep 17 00:00:00 2001 From: Yuji Ichikawa Date: Wed, 8 Jun 2016 13:23:06 +0900 Subject: [PATCH 1/2] JSON support for Collection API --- lib/twitter.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/twitter.js b/lib/twitter.js index f8e15a89..7f6cc04b 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -124,12 +124,17 @@ Twitter.prototype.__request = function(method, path, params, callback) { // Pass form data if post if (method === 'post') { - var formKey = 'form'; + if (this.options.request_options.json) { + options.body = params; + } + else { + var formKey = 'form'; - if (typeof params.media !== 'undefined') { - formKey = 'formData'; + if (typeof params.media !== 'undefined') { + formKey = 'formData'; + } + options[formKey] = params; } - options[formKey] = params; } this.request(options, function(error, response, data) { From 3fcec0c9c22555e2850de654cf644a8d1ae0b9bc Mon Sep 17 00:00:00 2001 From: Yuji Ichikawa Date: Fri, 30 Nov 2018 11:37:49 +0900 Subject: [PATCH 2/2] bugfix: body was object when json = true --- lib/twitter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter.js b/lib/twitter.js index fbe5d2fc..e663dfc0 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -163,7 +163,7 @@ Twitter.prototype.__request = function(method, path, params, callback) { if (data === '') { data = {}; } - else { + else if (typeof data === 'string') { data = JSON.parse(data); } }