Giter Site home page Giter Site logo

Comments (8)

edsu avatar edsu commented on July 21, 2024 4

I have submitted a PR with a fix #93. I really depend on this library in one of my projects and have adjusted my package.json to point to edsu/twitter-v2 until some kind of fix is available here.

from twitter-v2.

edsu avatar edsu commented on July 21, 2024 2

More notes on this (sorry if they aren't helping). It looks like there's a mismatch in how oauth-1.0a and twitter-v2 are encoding spaces ' '.

The problem is that URL.toString() encodes a space ' ' in a query paramter as + whereas encodeURIComponent() encodes a space ' ' as %20. Since the URL being GET doesn't match the URL that was signed Twitter's API is rightly throwing a 401.

> encodeURIComponent(' ')
'%20'
> u = new URL('http://example.com')
URL {
  href: 'http://example.com/',
  origin: 'http://example.com',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'example.com',
  hostname: 'example.com',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
> u.searchParams.set('foo', 'bar baz')
undefined
> u.toString()
'http://example.com/?foo=bar+baz'

from twitter-v2.

edsu avatar edsu commented on July 21, 2024 1

Thanks for reporting this. I've noticed that the 401 gets returned if the query is anything but a simple word. For example changing query to obama biden causes it too.

from twitter-v2.

edsu avatar edsu commented on July 21, 2024 1

Testing the equivalent query in Python leads me to the conclusion that the problem resides here in twitter-v2 and not on the Twitter side. This is good news because that means it should be easily fixable :-)

from twitter-v2.

edsu avatar edsu commented on July 21, 2024 1

I've added a unit test that demonstrates the problem, which is currently failing:

https://github.com/edsu/twitter-v2/blob/master/test/e2e/search.js#L72-L105

from twitter-v2.

rn4n avatar rn4n commented on July 21, 2024 1

@edsu In one of the projects that I contribute, I also switched to use your fork too. Thanks!

from twitter-v2.

edsu avatar edsu commented on July 21, 2024

I've also noticed that it will work if you don't configure your client with access_token_key and access_token_secret? This is what the twitter-v2 unit test is doing which passes with the complex query 'url:"https://medium.com" -is:retweet lang:en'.

I wonder if the v2 API rules around what can be done in queries are coming into play here? I wouldn't be completely surprised if it's a bug on Twitter's side too.

https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query#availability

from twitter-v2.

edsu avatar edsu commented on July 21, 2024

I might be wrong, but it appears that the space in the query parameter gets converted to a + when calling URL.toString() which is correct. But somewhere in the underlying call to oauth-1.0a/OAuth.authorize here any + in the URL are being converted to %20 prior to signing? This is causing the request authorization to be invalid.

from twitter-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.