Bug or Spec change (of Twitter API 1.1)

On my node application project, I have migrated Twitter API from v1.0 to v1.1. And I have found some errors in my log file.

Error

{"message":"Could not authenticate you","code":32}

Cause

This error occurs, if post data (to 1.1/statuses/update) is including...

  • !
  • '
  • (
  • )
  • *

Solution

I have patched node_modules/oauth/lib/oauth.js of node-oauth(only used node-twitter)...

from

327   if( (method == "POST" || method == "PUT")  && ( post_body == null && extra_params != null) ) {
328     post_body= querystring.stringify(extra_params);
329   }

to

 327   if( (method == "POST" || method == "PUT")  && ( post_body == null && extra_params != null) ) {
 328     post_body= querystring.stringify(extra_params);
+331     post_body= post_body.replace(/\!/g, "%21")
+332                         .replace(/\'/g, "%27")
+333                         .replace(/\(/g, "%28")
+334                         .replace(/\)/g, "%29")
+335                         .replace(/\*/g, "%2A");
 336   }

Twitter API v1.0 don't require this patch. Only v1.1 requires this patch double-escaping a post body. I think my patch is not universal, because this changing will make it impossible to use this library for any other oauth service...

My Questions

  • This is node-oauth problem or Twitter API problem (Twitter Spec chage or bug)?
  • Who should I report this problem to?

This is node-oauth problem or Twitter API problem (Twitter Spec chage or bug)?

quote from @episod:
"API v1.1 (and in general all of our APIs) are getting stricter with OAuth and HTTP. In the HTTP spec, some characters are required to be encoded in URLs and POST bodies, including parens and single quotes."

Who should I report this problem to?

here's the issue thread: https://dev.twitter.com/discussions/12821

I experienced this same problem too. I tried 2 different twitter libs (node-twitter and ntwitter). Both has same issue with 1.1 api. Your fix seems to have worked for me. Thanks for that! It is interesting that they apply this same fix on line 66. Not sure, but it looks like this is a bug with node-oauth. I would start by reporting it there. Your fix didn't seem to break the basic stuff I'm doing with facebook, so I hope that is a good sign that this fix is not affecting other libs.