[Python] Instagram python request to get access_token

Discussão em 'Python' iniciado por Stack, Maio 3, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create instagram authentication using a python request to get an access token

    router = APIRouter(prefix="/meta/instagram", tags=["instagram"])

    SCOPE = 'instagram_graph_user_profile,instagram_graph_user_media'

    @router.get("/auth")
    async def login(request: Request):
    state = secrets.token_hex(16)
    auth_url = 'https://api.instagram.com/oauth/authorize'
    payload = {
    'client_id': config.id_app_ig,
    'redirect_uri': config.redirect_uri_ig,
    'response_type': 'code',
    'state': state,
    'scope': SCOPE
    }
    complete_url = auth_url + urlencode(payload)
    return RedirectResponse(complete_url)

    @router.get("/auth2callback")
    async def token(code: str):
    token_url = 'https://api.instagram.com/oauth/access_token'
    payload = {
    'client_id': config.id_app_ig,
    'redirect_uri': config.redirect_uri_ig,
    'client_secret': config.secret_app_ig,
    'code': code
    }
    get_access_token = requests.post(token_url, data=payload)
    access_token = get_access_token.json().get("access_token")
    return JSONResponse (access_token)


    but always error like this: [​IMG]

    can somebody help me with this eror

    Continue reading...

Compartilhe esta Página