jublo / codebird-js

A Twitter library in JavaScript.
https://www.jublo.net/projects/codebird/js
GNU General Public License v3.0
384 stars 97 forks source link

Runtime error when parsing error response from Twitter #156

Closed araskin closed 6 years ago

araskin commented 6 years ago

In the _parseAPIReply there is a run time error when parsing an XML response from Twitter. pastedgraphic-1

It seems that Twitter is responding slightly differently then what the RegEx is expecting and this is causing the call to match to return a null and not an array. Therefore the [1] causes a run time error.

Here is a screen shot of the reply variable. The code="415" is causing the issue. pastedgraphic-3

mynetx commented 6 years ago

Hey @araskin, thanks for catching that! I’ll go and fix it right away. 😌

mynetx commented 6 years ago

@araskin Please test the version in https://github.com/jublonet/codebird-js/tree/405139e21ccee15777654eb0258159135ddda9aa – either codebird.es7.js or codebird.js, depending on your environment. Please let me know whether this works for you.

Here’s an example:

// gets a request token
cb.__call("oauth_requestToken", { oauth_callback: "oob" }, function(
  reply,
  rate,
  err
) {
  if (err) {
    console.log("error response or timeout exceeded" + err.error);
  }
  if (reply) {
    if (reply.errors && reply.errors["415"]) {
      // check your callback URL
      console.log(reply.errors["415"]);
      return;
    }

    // stores the token
    cb.setToken(reply.oauth_token, reply.oauth_token_secret);

    // gets the authorize screen URL
    cb.__call("oauth_authorize", {}, function(auth_url) {
      window.codebird_auth = window.open(auth_url);
    });
  }
});