Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Bug or Spec change (of Twitter API 1.1)

Bug or Spec change (of Twitter API 1.1)

Problem

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?
Problem courtesy of: Mitsuaki Ishimoto

Solution

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.

Solution courtesy of: tpneumat

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Bug or Spec change (of Twitter API 1.1)

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×