Hi there,
I’ve setup 2 postman requests to query /2/tweets/search/recent. It works if I use an oauth2 bearer token, but not if I use oauth 1.0a. I’ve tested the oauth 1.0a keys (consumer + access) on another endpoint (the /2/tweets endpoint) and they work correctly.

The error response is:

{
    "title": "Unauthorized",
    "type": "about:blank",
    "status": 401,
    "detail": "Unauthorized"
}

Here’s another demo using twitter-v2 npm package:

const Twitter = require("twitter-v2");
const KEY = require("./keys");

const client = new Twitter({
  consumer_key: KEY.ilancopelyn.consumer_key,
  consumer_secret: KEY.ilancopelyn.consumer_secret,
  access_token_key: KEY.ilancopelyn.access_token,
  access_token_secret: KEY.ilancopelyn.access_token_secret,
});

async function getTweet(ids) {
  const {data} = await client.get("tweets", {ids});
  console.log(data);
}

async function search() {
  const {data} = await client.get("tweets/search/recent", {
    max_results: 10,
    start_time: "2021-04-22T00:00:00Z",
    end_time: "2021-04-22T10:00:00Z",
    query: "coffee -is:retweet",
  });
  console.log(data);
}

async function run() {
  try {
    await getTweet("1228393702244134912");
    await search();
  } catch (e) {
    console.error(e);
  }
}

run();

Results:

[
  {
    id: '1228393702244134912',
    text: 'What did the developer write in their Valentine’s card?\n' +
      '  \n' +
      'while(true) {\n' +
      '    I = Love(You);  \n' +
      '}'
  }
]
TwitterError: Unauthorized
    at Function.module.exports.fromJson (/strive/dev/node_modules/twitter-v2/build/TwitterError.js:23:16)
    at Twitter.get (/strive/dev/node_modules/twitter-v2/build/twitter.js:43:49)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async search (/strive/dev/tools/twitter-v2/src/4-search-recent-user.js:17:18)
    at async run (/strive/dev/tools/twitter-v2/src/4-search-recent-user.js:29:5) {
  code: 401,
  details: 'Unauthorized'
}
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.