I’m working on an image-posting script from within Google Apps Script, and I can’t seem to get posting to https://upload.twitter.com/1.1/media/upload.json to work correctly.
After trying to build my own multipart form by concatenating all the bytes together, I’ve reduced the overhead to just one blob (type image/jpeg) in the payload. The options object looks like this:
var options = {
“oAuthServiceName”:“twitter”,
“oAuthUseToken”:“always”,
method: “POST”,
contentType: “multipart/form-data”,
payload: { “media[]” : imageblob }
};
where imageblob is a Blob (apps script type for handling binary data) containg the bin data for a JPEG and the image/jpeg content type.
One sample of the request object that’s created:
[14-11-20 06:23:11:240 PST]
{“headers”:{
“X-Forwarded-For”:”174.140.111.67”
},
“oAuthServiceName”:“twitter”,
“useIntranet”:false,
“followRedirects”:true,
“payload”:”-------wlinujDVABg2j6YW82NGhFaaNR5eDBAHsXqTWd1VmQHMTXtX7H\r\nContent-Disposition: form-data; name=“media[]”; filename=“edt35.jpg”\r\nContent-type: image/jpeg\r\n\r\n
[binary data truncated]
\r\n-------wlinujDVABg2j6YW82NGhFaaNR5eDBAHsXqTWd1VmQHMTXtX7H–\r\n”,
“oAuthUseToken”:"always”,
“method”:"post”,
“contentType”:"multipart/form-data”,
“validateHttpsCertificates”:true,
“url”:"https://upload.twitter.com/1.1/media/upload.json”
}
And what I get back is always:
{ "errors”: [{“code”:38,“message”:“media parameter is missing.”}]}
So I’ve tried every naming permutation (media, media[], media_data, media_data[]) and none of these produce any different an answer. The format of the form data being sent seems correct, so I am rather at a loss for what I’m doing wrong. Anyone dealt with this before?