|
3 | 3 | You can adapt this file completely to your liking, but it should at least |
4 | 4 | contain the root `toctree` directive. |
5 | 5 |
|
6 | | -Welcome to The Box Python SDK's documentation! |
7 | | -=================================== |
| 6 | +Box Python SDK |
| 7 | +============== |
8 | 8 |
|
9 | | -Contents: |
| 9 | + |
| 10 | +Installing |
| 11 | +---------- |
| 12 | + |
| 13 | +.. code-block:: console |
| 14 | +
|
| 15 | + pip install boxsdk |
| 16 | +
|
| 17 | +
|
| 18 | +Source Code |
| 19 | +----------- |
| 20 | + |
| 21 | +https://github.com/box/box-python-sdk |
| 22 | + |
| 23 | + |
| 24 | +Quickstart |
| 25 | +---------- |
| 26 | + |
| 27 | +Create a developer token from your app's configuration page (https://app.box.com/developers/services). |
| 28 | + |
| 29 | +You'll be prompted for it on the command line. |
| 30 | + |
| 31 | +.. code-block:: pycon |
| 32 | +
|
| 33 | + $ from boxsdk import DevelopmentClient |
| 34 | + $ client = DevelopmentClient() |
| 35 | + >>> Enter developer token: <enter your developer token> |
| 36 | + $ me = client.user().get() |
| 37 | +
|
| 38 | + GET https://api.box.com/2.0/users/me {'headers': {u'Authorization': u'Bearer ----KkeV', |
| 39 | + u'User-Agent': u'box-python-sdk-1.4.3'}, |
| 40 | + 'params': None} |
| 41 | +
|
| 42 | + {"type":"user","id":"----6009","name":"Jeffrey Meadows","login":"[email protected]",...} |
| 43 | +
|
| 44 | + $ me.name |
| 45 | + >>> Jeffrey Meadows |
| 46 | +
|
| 47 | +The ``DevelopmentClient`` uses Box developer tokens for auth (and will prompt you for a new token upon |
| 48 | +expiration), and logs API requests and responses, making it really easy to get started learning the SDK and Box API. |
| 49 | + |
| 50 | + |
| 51 | +Creating an App for Users |
| 52 | +------------------------- |
| 53 | + |
| 54 | +Authorization |
| 55 | +~~~~~~~~~~~~~ |
| 56 | + |
| 57 | +If you'd like other users to use your app, you need to set up a way for them to authorize your app and |
| 58 | +grant it access to their Box account. The ``auth`` module contains several classes to help you do that. |
| 59 | + |
| 60 | +The simplest class is the ``OAuth2`` class. To use it, instantiate it with your ``client_id`` and ``client_secret``. |
| 61 | + |
| 62 | +Follow the `tutorial on GitHub <https://github.com/box/box-python-sdk/blob/master/README.rst#id2>`_ for |
| 63 | +instructions on how to get an authorized client for a user. Using the ``store_tokens`` callback, you may persist |
| 64 | +the user's auth and refresh tokens for the next time they use your app. Once they return to your app, you can |
| 65 | +create an authorized client like so: |
| 66 | + |
| 67 | +.. code-block:: python |
| 68 | +
|
| 69 | + from boxsdk import OAuth2, Client |
| 70 | +
|
| 71 | + oauth = OAuth2( |
| 72 | + client_id='YOUR_CLIENT_ID', |
| 73 | + client_secret='YOUR_CLIENT_SECRET', |
| 74 | + store_tokens=your_store_tokens_callback_method, |
| 75 | + access_token=persisted_access_token, |
| 76 | + refresh_token=persisted_refresh_token, |
| 77 | + ) |
| 78 | + client = Client(oauth) |
| 79 | +
|
| 80 | +
|
| 81 | +Making requests to Box |
| 82 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 83 | + |
| 84 | +Once you have an authorized client, you can use it to make requests to Box on your user's behalf. The client |
| 85 | +has several methods to help you get started, many of which return Box objects, which, in turn, have methods that |
| 86 | +correspond to Box API endpoints. |
| 87 | + |
| 88 | +The module documentation below describes each of these methods and which parameters they require. Some API endpoints |
| 89 | +do not have corresponding SDK methods; for those, you can use the generic ``make_request`` method of the client. |
| 90 | + |
| 91 | +Module Documentation |
| 92 | +-------------------- |
10 | 93 |
|
11 | 94 | .. toctree:: |
12 | | - :maxdepth: 4 |
| 95 | + :maxdepth: 4 |
13 | 96 |
|
14 | | - boxsdk |
| 97 | + boxsdk |
15 | 98 |
|
16 | 99 |
|
17 | 100 | Indices and tables |
|
0 commit comments