Comments (8)
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.
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.
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.
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.
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.
@edsu In one of the projects that I contribute, I also switched to use your fork too. Thanks!
from twitter-v2.
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.
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)
- OAuth2 Application-based?
- [BUG] Twitter deep links don't linking to the intended page
- TypeError: url_1.URL is not a constructor HOT 1
- error code 410 error description unauthorized
- Error on adding multiple query parameters separated by space, in urlParams HOT 2
- Provide support for filtered streams HOT 3
- Filtered stream disconnected every 5 minutes HOT 3
- More streaming examples HOT 3
- User fields not returning any data HOT 2
- Lost in Documentation, how to get all tweets by user? HOT 1
- Export types/interfaces/etc from central index.ts file for consumer usage
- Sample codes for client.post(path, body, urlParams); HOT 2
- expansions missing and example HOT 1
- Iteration through paginated data HOT 2
- Handle .errors[] in streams
- Can't resolve 'crypto' in '/project/node_modules/twitter-v2/build' HOT 2
- Unauthorized when POST to Tweets endpoint HOT 8
- This doesn't work. Twitter API gives you 5 values. You only have variables for 4 of them. Get 'unauthorized' when trying to use values you suggest. HOT 1
- I can't reply to a specific tweet
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twitter-v2.