Update with media error


#1

Hi,

I’m using NodeJS to post statuses and it works perfectly
for simple status text but no longer for attached image.
Migrating to v1.1 API now I get this error response:
{“code”:195,“message”:“Missing or invalid url parameter”}.

If an image is included to the post I only change
statuses/update.json url to statuses/update_with_media.json,
adding the parameter media / media[]. Before, when using v1
I uploaded the image to upload.twitter.com with
a random boundary but now I don’t know to do
because the API doesn’t accept anything I try.

I attach the code I’m using with https.request method below.
Thanks a lot.

	oa = new OAuth("https://api.twitter.com/oauth/request_token",
	      "https://api.twitter.com/oauth/access_token",
	      TWITTER_CONSUMER_KEY,
      		TWITTER_CONSUMER_SECRET,
	      "1.0A", null, "HMAC-SHA1"
	    );
	  var data = {};
	  data['status'] = text;

		if (image){
			action = 'update_with_media.json';
			data['media'] = fs.readFileSync(path+'/'+image);
		} else action = 'update.json';

		data = querystring.stringify(data);

		var authorization = oa.authHeader('https://api.twitter.com/1.1/statuses/'+action,
     			 access.keys.token, access.keys.tokenSecret, 'POST');

		var options = {
		  hostname: url,
      		  port: 443,
		  path: '/1.1/statuses/'+action,
		  method: 'POST',
		  headers: {
			'Authorization': authorization,
			'Content-Length': data.length,
      			'Connection': 'Keep-Alive'
  			}
		};

		var request = http.request(options), res='';

		request.write(data);
		request.end();

		request.on('error', function (err) {
      			// some stuff
  		});

		request.on('response', function (response) {
	   	response.setEncoding('utf8');            
	    	response.on('data', function (chunk) {
	      		res = chunk.toString();
	    });
	    response.on('end', function (resp) {
	    	console.log('Twitter API END', res, resp);
	    	if (!resp) // return error
	      console.log( resp.statusCode!==200 ? { error: resp, response: res } : { response: res });
	    });
	  });