-
Hi just wanted to ask why I keep getting error code 401 for my backend requests. I used bearer token for authentication. Code Sample: import { TwitterApi } from "twitter-api-v2";
import Endpoint from "../interface/Endpoint";
const SampleEndpoint: Endpoint = {
path: "/twitter/timeline",
async responder(req, res, next) {
const twitterClient = new TwitterApi(process.env.TWITTER_BEARER_TOKEN!);
// const roClient = twitterClient.readOnly;
const user = await twitterClient.v2.userByUsername("someuser");
console.log(user);
},
};
export default SampleEndpoint; Am I doing it right?? Are there any problems to my code? Any form of help is much appreciated! Thank you!! |
Beta Was this translation helpful? Give feedback.
Answered by
alkihis
Nov 19, 2021
Replies: 1 comment 1 reply
-
Hello, In theory, your code is correct. Can you copy/paste the thrown error? If you want more request info, you can add, at the beginning of your script: import { TwitterApiV2Settings } from 'twitter-api-v2';
TwitterApiV2Settings.debug = true It will print sent headers, authentification and request data. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
alkihis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
In theory, your code is correct.
Are you sure your bearer token is right and your ENV variable is correctly initialized?
Can you copy/paste the thrown error?
If you want more request info, you can add, at the beginning of your script:
It will print sent headers, authentification and request data.