如何检索框权限的登录代码

2024-04-25 19:09:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从要在python代码中操作的框中检索文件,但是我无法通过python登录。我已经到了允许通过web浏览器访问的地步,如here所述,我可以在授权后在url中看到代码,但我不知道如何以编程方式将代码输入到脚本中

以下是我到目前为止的情况:


sdk = OAuth2(
        client_id='[id]',
        client_secret='[secret]'
    )

    auth_url, csrf_token = sdk.get_authorization_url \
        ('https://account.box.com/api/oauth2/authorize?client_id=[id]&redirect_uri=https://account.box.com/api/oauth2/authorize8&response_type=code')

    webbrowser.open(auth_url)

    authentication_url = "https://api.box.com/oauth2/token";

    params = urlencode({
        'grant_type': 'authorization_code',
        'assertion': '[CODE]', # this is what I am looking to get
        'client_id': '[id]',
        'client_secret': '[secret]'
    }).encode()

    request = Request(authentication_url, params)
    response = urlopen(request).read()
    access_token = json.loads(response)['access_token']

谢谢你的帮助


Tags: 代码httpscomboxclienttokenauthapi