Question

New to the api ,new to using api need some help in writing a simple python code to retrieve oauth token

  • 25 March 2021
  • 4 replies
  • 795 views

Can someone please help me writing a simple python script to get the oauth token using api.

,

need some help in writing a simple python code to retrieve oauth token


4 replies

Userlevel 1

See this tutorial. Or this quick started sample using the Python SDK.

Is there a example without using the sdk

because when i use SDK i keep getting this error

ImportError: cannot import name 'SDK' from partially initialized module 'ringcentral' (most likely due to a circular import)

Userlevel 1

That is the tutorial is about "Access RingCentral platform services using Python native API."

Userlevel 1

I don't know what you want to refer to. That code is the RingCentral Python SDK, which helps developers easier to login RingCentral platform. It can be used to login with password flow or OAuth authorization.

To be honest, I don't know what you want to do as your original question is about how to retrieve auth token.

After you log in either ways, you will get the access tokens. And this sample code helps you to achieve the tokens via OAuth. Your problem is you don't know Flask so you cannot use the code as such. But it should help with the basic steps.

https://developers.ringcentral.com/guide/authentication/quick-start#python


@app.route('/oauth2callback', methods=['GET'])
def oauth2callback():
    platform = rcsdk.platform()
    auth_code = request.values.get('code')
    platform.login('', '', '', auth_code, RINGCENTRAL_REDIRECT_URL)
    tokens = platform.auth().data()
    session['sessionAccessToken'] = tokens
    return render_template('test.html')

Reply