Example of Explicit Authentication:
Explicit authentication is relatively straightforward with Stack.PY. Assuming you have already registered your applicationregistered your application, the instructions look something like this:
Visit your application's pageapplication's page to obtain the following information:
- key
- client ID
- client secret
Provide Stack.PY with the above information:
from stackpy import API # Fill in the strings with the appropriate values: API.key, API.client_id, API.client_secret = "", "", ""
The
API.begin_explicit()
call consists of the following parameters:- a string consisting of the required privileges separated by commas
- the URI to redirect the user to when the authorization completes
- an optional string value to be returned with the access token when authorization completes
Example:
redirect_uri = API.begin_explicit('read_inbox,no_expiry', 'http://example.com/done')
The return value of the function is the URL that you will need to redirect the user to. That page will allow the user to authorize your application.
The
API.complete_explicit()
call consists of the following parameters:- the value of the GET parameter
code
- the URI you provided to
begin_explicit()
above
Example:
access_token = API.complete_explicit(request.GET['code'], 'http://example.com/done')
The return value is the access token for the user.
- the value of the GET parameter