|
| 1 | +# Quickstart: Run a Drive App in Python |
| 2 | + |
| 3 | +Complete the steps described in the rest of this page, and in about five minutes |
| 4 | +you'll have a simple Drive app that uploads a file to Google Drive. |
| 5 | + |
| 6 | +To run a quickstart example you'll need: |
| 7 | + |
| 8 | +* Access to the internet and a web browser, in order to authorize the sample app. |
| 9 | +* A Google account with Drive enabled. |
| 10 | +* An environment to run programs in your selected language. |
| 11 | + |
| 12 | +Step 1: Get the sample |
| 13 | +-- |
| 14 | + |
| 15 | +Clone the `git` repository at `https://github.com/googledrive/quickstart-python`. |
| 16 | + |
| 17 | + git clone https://github.com/googledrive/quickstart-python |
| 18 | + |
| 19 | +Step 2: Install the Google Client Library |
| 20 | +-- |
| 21 | + |
| 22 | +To install the Google API Python Client on a system, you should use the `pip` command. |
| 23 | + |
| 24 | + pip install --upgrade google-api-python-client |
| 25 | + |
| 26 | +Alternatively, if you are using `virtualenv`, create the environment and install the client library. |
| 27 | + |
| 28 | + virtualenv ve |
| 29 | + ./ve/bin/pip install --upgrade google-api-python-client |
| 30 | + |
| 31 | +If you need to access the Google API Python Client from a Google App Engine |
| 32 | +project, you can follow the instructions |
| 33 | +[here](https://developers.google.com/api-client-library/python/platforms/google_app_engine). |
| 34 | + |
| 35 | + |
| 36 | +Step 3: Run the sample |
| 37 | +-- |
| 38 | + |
| 39 | +After you have set up your Google API project, installed the Google API client |
| 40 | +library, and set up the sample source code, the sample is ready to run. |
| 41 | + |
| 42 | + python main.py |
| 43 | + |
| 44 | +Or if using `virtualenv`. |
| 45 | + |
| 46 | + ./ve/bin/python main.py |
| 47 | + |
| 48 | +When you run the sample from command-line, it provides a link you'll need to |
| 49 | +visit in order to authorize. |
| 50 | + |
| 51 | +1. Browse to the provided URL in your web browser. |
| 52 | +2. If you are not already logged into your Google account, you will be prompted |
| 53 | + to log in. If you are logged into multiple Google accounts, you will be |
| 54 | + asked to select one account to use for the authorization. |
| 55 | +3. Copy the code you're given after browsing to the link, and paste it into the |
| 56 | + prompt `Enter authorization code:`. Click **Enter**. |
| 57 | + |
| 58 | +Note: The authorization flow in this example is greatly simplified for |
| 59 | +demonstration purposes and should not be used in web applications. For more |
| 60 | +information, see [Authorizing your App with Google Drive](http://developers.google.com/drive/about-auth). |
| 61 | + |
| 62 | +When you finish these steps, |
| 63 | +the sample prints information about the Google Drive file to the screen. |
| 64 | +The file `document.txt` is accessible in Google Drive, and is titled `My |
| 65 | +New Text Document`. |
| 66 | + |
| 67 | +By editing the sample code to provide paths to new files and new titles, |
| 68 | +you can run a few more simple upload tests. When you're ready, you |
| 69 | +could try running some other Drive API methods such as |
| 70 | +[files.list](http://developers.google.com/drive/v2/reference/files/list). |
| 71 | +>>>>>>> old_a/master |
0 commit comments