Preformatted text I am doing login with twitter using oauth2.0
Following these steps:

  1. “url?response_type=code&client_id={client-id}&redirect_uri=http://localhost:3000/signup&scope=tweet.read%20users.read%20follows.read%20follows.write&state=state&code_challenge=challenge&code_challenge_method=plain”
  2. “url/oauth2/authorize?response_type=code&client_id={client-id}&redirect_uri=http://localhost:3000/signup&scope=tweet.read%20users.read%20follows.read%20follows.write&state=state&code_challenge=challenge&code_challenge_method=plain”
  3. And to get access token , I am using this
const test = btoa(apikey + ":" + apiSecret);
let data = {
        grant_type: "authorization_code",
        code: code.toString(),
        client_id: "id",
        redirect_uri: "http://localhost:3000/signup",
        code_verifier: "challenge",
      };
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",

          Authorization: "Basic " + test,
        },
      };
      axios
        .post(
          "https://api.twitter.com/2/oauth2/token",
          new URLSearchParams(data),
          config
        )
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
    
        });

Hi AdityaGathania,

According to the documentation, on the parameter “grant_type” of the endpoint “oauth2/token”, only “client_credentials” is allowed at this time.

Addition to that, you can modify the parameters and request data. It seems you don’t need to add additional request body to the request, when you only want to retrieve the token.

I think the “Example request” on the document using curl will be helpful to you.

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