使用 Django 的 RingCentral OAuth

RingCentral OAuth with Django

我正在使用 Django 完成 RingCentral 的授权流程快速启动应用程序。这需要对 Flask code provided 进行一些更改,但大部分流程都在运行。索引页面将我发送到 RingCentral 登录,然后将我发送回测试页面。但是当我点击那个页面上的三个链接中的任何一个时,我得到了同样的错误:

AttributeError at /test/
'bytes' object has no attribute 'get'

这是处理测试页面的 Django 视图(根据提供的 Flask 代码稍作修改):

def test(request):
    platform = SyncConfig.rcsdk.platform()
    platform.auth().set_data(request.session['sessionAccessToken'])
    if platform.logged_in() == False:
        return index(request)
        api = request.GET.get('api')
    if api == "extension":
        resp = platform.get("/restapi/v1.0/account/~/extension")
        return resp.response()._content
    elif api == "extension-call-log":
        resp = platform.get("/restapi/v1.0/account/~/extension/~/call-log")
        return resp.response()._content
    elif api == "account-call-log":
        resp = platform.get("/restapi/v1.0/account/~/call-log")
        return resp.response()._content
    else:
        return render(request, 'sync/test.html')

和sync/test.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
  <b><a href="/logout">Logout</a></b>
  <h2>Call APIs</h2>
  <ul>
      <li><a href="/test?api=extension">Read Extension Info</a></li>
      <li><a href="/test?api=extension-call-log">Read Extension Call Log</a></li>
      <li><a href="/test?api=account-call-log">Read Account Call Log</a></li>
  </ul>
</body>
</html>

有没有人为 RingCentral 设置 Django 授权流程,可以告诉我哪里出了问题?

我明白了。简单地从视图返回 resp.response()._content 会导致 Django 问题。我写了一个简单的视图来显示数据并返回呈现的模板,上下文中包含 resp.response()._content

def test(request):
    platform = SyncConfig.rcsdk.platform()
    platform.auth().set_data(request.session['sessionAccessToken'])
    if platform.logged_in() == False:
        return index(request)
    api = request.GET.get('api')
    if api == "extension":
        resp = platform.get("/restapi/v1.0/account/~/extension")
        content = json.loads(resp.response()._content)
        return render(request, 'sync/response.html', {'content': content})
    elif api == "extension-call-log":
        resp = platform.get("/restapi/v1.0/account/~/extension/~/call-log")
        content = json.loads(resp.response()._content)
        return render(request, 'sync/response.html', {'content': content})
    elif api == "account-call-log":
        resp = platform.get("/restapi/v1.0/account/~/call-log")
        content = json.loads(resp.response()._content)
        return render(request, 'sync/response.html', {'content': content})
    else:
        return render(request, 'sync/test.html')

这里是sync/response.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
    <b><a href="/logout">Logout</a></b>
    <h2>API Response</h2>
    <ul>
        {% for k, v in content.items %}
            <li>{{ k }}: {{ v }}</li>
        {% endfor %}
    </ul>
</body>
</html>