Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on adding multiple query parameters separated by space, in urlParams #79

Open
1 task done
pbshgthm opened this issue May 2, 2021 · 2 comments
Open
1 task done

Comments

@pbshgthm
Copy link

pbshgthm commented May 2, 2021

Prerequisites

  • Put an X between the brackets on this line if you have done all of the
    following:
    • Checked that your issue isn't already filed: [open issues]
    • Checked the [bug report guidelines]

Description

When adding multiple query operators in urlParams in the form of an object, it throws an error. On checking it closely, it looks like the error is due to url module in applyParameters function in the source code that encodes space between the parameters as + and Twitter API expects it to be encoded as %20. The code mentioned in the examples results in the same error.

Steps to Reproduce

node v12, v14, v16

const urlParams = {
  'query' : 'conversation_id:1305403243388829696 from:pbshgthm',
 ...other_params
}

client.get(`tweets/search/recent`,urlParams);

Expected behavior:

conversation_id:1305403243388829696 from:pbshgthm gets encoded as conversation_id%3A1305403243388829696%20from%3Apbshgthm

API call goes through

Actual behavior:

conversation_id:1305403243388829696 from:pbshgthm gets encoded as conversation_id%3A1305403243388829696+from%3Apbshgthm

Results in the following error

handledPromiseRejectionWarning: Error: Unauthorized at Function.module.exports.fromJson (/home/runner/threads/node_modules/twitter-v2/build/TwitterError.js:23:16)

Reproduces how often:

Always

Versions

1.1.0 (latest)

Additional Information

N.A.

@pbshgthm pbshgthm changed the title Error on adding multiple query parameter in search endpoint Error on adding multiple query parameters separated by space, in urlParams May 2, 2021
@everythingguy
Copy link

As a temporary solution, I went into the twitter.js file and added this line "url.href = url.href.replaceAll("+", "%20");" after applyParameters in the get function.

@DavidLibeau
Copy link

As a temporary solution, I went into the twitter.js file and added this line "url.href = url.href.replaceAll("+", "%20");" after applyParameters in the get function.

Is there a better solution? If not, we should make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants