Facing an issue where after I set up the code that tweepy suggest, I get a missing code error. I am able to get the authorization link but once I try to fetch_token, I get this error.


I am fairly new to the Twitter API so any suggestions would be helpful!

    oauth2_user_handler = tweepy.OAuth2UserHandler(
    client_id = settings.CLIENT_ID,
    redirect_uri="http://127.0.0.1:8000/oauth",
    scope = ["tweet.write", "tweet.read", "offline.access"]
) 
    auth_link = oauth2_user_handler.get_authorization_url()
    access_token = oauth2_user_handler.fetch_token(auth_link)
    client = tweepy.Client(access_token['access_token'])

usually need further investigation to analyze the error
If you look at the error message, it’s most likely a mismatch between the challenge code and the verifier code

1 Like

Thank you for the response, I am seeing that as the exact error, I am having a hard time figuring out why that is. Am I feeding the wrong information into the fetch_token line? Because to code works without that line. Or is it something along the lines of missing parameters? I’m relatively new to this so idk exactly where I go from here.

oauth2_user_handler.fetch_token() needs Response URL, not the Authorization URL.

You’ll need to print auth_link then visit that link in the browser then click Authorize.

After clicking Authorize, it will redirect you to a page that you specified in the Callback URL. (Even if the page is invalid)

Copy the Callback URL with the code and use that as your Response URL. :slight_smile: