twitter-v2 icon indicating copy to clipboard operation
twitter-v2 copied to clipboard

Error: Unauthorized when using tweets/search/all

Open dolanmiu opened this issue 4 years ago • 4 comments

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.

dolanmiu avatar Apr 16 '21 21:04 dolanmiu

I had a similar issue when trying the streams API for 'tweets/search/stream'. Switching to a bearer token solved it for me.

ErikKalkoken avatar Apr 19 '21 00:04 ErikKalkoken

@ErikKalkoken How do I switch to Bearer token?

Got a code sample?

dolanmiu avatar Apr 19 '21 00:04 dolanmiu

@dolanmiu

I used the example from the README:

const client = new Twitter({
  bearer_token: '',
});

ErikKalkoken avatar Apr 19 '21 02:04 ErikKalkoken

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.

HunterLarco avatar Apr 20 '21 13:04 HunterLarco