twitter-v2
twitter-v2 copied to clipboard
Error: Unauthorized when using tweets/search/all
It works 100% perfectly when tweets/search/recent, but as soon as I switch to tweets/search/all, it falls apart
Works:
const { data } = await client.get("tweets/search/recent", { query: "test" });
Does not work:
const { data } = await client.get("tweets/search/all", {
query: "test",
start_time: yesterday.toUTCString(),
end_time: new Date().toUTCString()
});
If it omit start_time and end_time, it gives:
Error: Unsupported Authentication: Authentication with OAuth 1.0a User Context is forbidden. Please, make the request with OAuth 2.0 Bearer Token authentication.
I had a similar issue when trying the streams API for 'tweets/search/stream'. Switching to a bearer token solved it for me.
@ErikKalkoken How do I switch to Bearer token?
Got a code sample?
@dolanmiu
I used the example from the README:
const client = new Twitter({
bearer_token: '',
});
Note that the tweets/search/all is only available to users who have been approved for the Academic Research product track. See twitter documentation for details.
I suspect you're seeing authentication errors because tweets/search/recent is available to every API user unlike the all corpus.
Unfortunately auth failures such as this one tend to be very cryptic.