question

Sagar Arora avatar image
Sagar Arora asked Phong Vu answered

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

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

api auth
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered Phong Vu edited

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

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Sagar Arora avatar image
Sagar Arora answered Sagar Arora commented

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)

12 comments
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

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

0 Likes 0 ·

So the thing with native api example is that it needs 'password': os.getenv("RC_PASSWORD")

but we have enabled sso on our account so how will that work?

0 Likes 0 ·

Will the app password work in this scenario?

0 Likes 0 ·

It depends on the account SSO settings. Most of the cases is that it'll not support password flow after enabling SSO.

Implement 3-legged authentication login requires you writing lots of codes. That is why I recommend you to use the SDK. Your problem is your environment and I don't know how you set/install the RingCentral Python SDK. you should solve that problem or then look at the source code of the SDK to implement your own. https://github.com/ringcentral/ringcentral-python

0 Likes 0 ·
Show more comments
Phong Vu avatar image
Phong Vu answered

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')
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys