I'm trying to get the user's email when they login so I can add it to their user document however whenever I use the await client.v1.verifyCredentials({ include_email: true });
it always returns a 403 with a message saying You are not permitted to use OAuth2 on this endpoint
.
I'm using the twitter-api-v2
node.js library and using OAuth2 to login the users.
Here's the full code for more context:
let client, accessToken, refreshToken;
try {
const data = await twitter.loginWithOAuth2({
code,
codeVerifier: token.codeVerifier,
redirectUri: callbackUrl,
});
client = data.client;
accessToken = data.accessToken;
refreshToken = data.refreshToken;
} catch (err) {
console.error(err);
return res.status(400).json({ msg: "Twitter tokens have expired." });
}
let data;
try {
const response = await client.v2.me({
"user.fields": ["profile_image_url"],
});
data = response.data;
} catch (err) {
console.error(err);
return res
.status(500)
.json({ msg: "Failed to get your account from Twitter!" });
}
// here is the problem
try {
const response = await client.v1.verifyCredentials({ include_email: true });
console.log(response);
} catch (err) {
console.error(err);
return res
.status(500)
.json({ msg: "Failed to get your email from Twitter!" });
}
I have a feeling that maybe I'm not using the right permissions on the twitter developer dashboard (although I am requesting the user's email in the dashboard) or I'm not requesting the correct scopes when the OAuth link is generated so does anyone have a suggestion about how I can continue?
Thanks in advance!