title: What is the meaning of these errors I received when using the Twitter API?
body: <p>Here is my code, I am trying to make an AI Twitter Bot using the Twitter API &amp; Firebase:</p>
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp();
  const dbRef = admin.firestore().doc('tokens/cvstate');
  const dbRef2 = admin.firestore().doc('tokens/access')
  
  const TwitterApi = require('twitter-api-v2').default;
  const twitterClient = new TwitterApi({
    clientId: 'MY_ID',
    clientSecret: 'MY_SECRET',
  });
  
  const callbackURL = 'MY CALLBACK URL';
  
  const { Configuration, OpenAIApi } = require('openai');
  const configuration = new Configuration({
    organization: 'MY ORG',
    apiKey: 'MY KEY',
  });
  const openai = new OpenAIApi(configuration);
  
  exports.auth = functions.https.onRequest(async (request, response) =&gt; {
    const { url, codeVerifier, state } = twitterClient.generateOAuth2AuthLink(
      callbackURL,
      { scope: ['tweet.read', 'tweet.write', 'users.read', 'offline.access'] }
    );
    await dbRef.set({ codeVerifier, state });
  
    response.redirect(url);
  });
  
  exports.callback = functions.https.onRequest(async (request, response) =&gt; {
    const { state, code } = request.query;
  
    const dbSnapshot = await dbRef.get();
    const { codeVerifier, state: storedState } = dbSnapshot.data();
  
    if (state !== storedState) {
      return response.status(400).send('Stored tokens not match.');
    }
  
    const {
      client: loggedClient,
      accessToken,
      refreshToken,
    } = await twitterClient.loginWithOAuth2({
      code,
      codeVerifier,
      redirectUri: callbackURL,
    });
  
    await dbRef2.set({ accessToken, refreshToken });
  
    const { data } = await loggedClient.v2.me(); 
  
    response.send(data);
  });
  
  exports.newTweet = functions.https.onRequest(async (request, response) =&gt; {
    const { refreshToken } = (await dbRef2.get()).data();
  
    const {
      client: refreshedClient,
      accessToken,
      refreshToken: newRefreshToken,
    } = await twitterClient.refreshOAuth2Token(refreshToken);
  
    await dbRef2.set({ accessToken, refreshToken: newRefreshToken });
  
    const newTweet = await openai.createCompletion('text-davinci-001', {
      prompt: 'tweet something political',
      max_tokens: 64,
    });
  
    const { data } = await refreshedClient.v2.tweet(
      newTweet.data.choices[0].text
    );
  
    response.send(data);
  });
  </code></pre>
  <p>Auth &amp; Callback commands work, however when I run the auth command I get the following error message:</p>
  <blockquote>
  <p>Error: Request failed with status code 401 at createError (/home/cog9/TwitterBot/functions/node_modules/axios/lib/core/createError.js:16:15) at settle (/home/cog9/TwitterBot/functions/node_modules/axios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamEnd (/home/cog9/TwitterBot/functions/node_modules/axios/lib/adapters/http.js:322:11) at IncomingMessage.emit (node:events:402:35) at endReadableNT (node:internal/streams/readable:1343:12) at processTicksAndRejections (node:internal/process/task_queues:83:21)</p>
  </blockquote>