1<?xml version="1.0" encoding="ascii"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 3 "DTD/xhtml1-transitional.dtd"> 4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 5<head> 6 <title>googleapiclient.sample_tools</title> 7 <link rel="stylesheet" href="epydoc.css" type="text/css" /> 8 <script type="text/javascript" src="epydoc.js"></script> 9</head> 10 11<body bgcolor="white" text="black" link="blue" vlink="#204080" 12 alink="#204080"> 13<!-- ==================== NAVIGATION BAR ==================== --> 14<table class="navbar" border="0" width="100%" cellpadding="0" 15 bgcolor="#a0c0ff" cellspacing="0"> 16 <tr valign="middle"> 17 <!-- Home link --> 18 <th> <a 19 href="googleapiclient-module.html">Home</a> </th> 20 21 <!-- Tree link --> 22 <th> <a 23 href="module-tree.html">Trees</a> </th> 24 25 <!-- Index link --> 26 <th> <a 27 href="identifier-index.html">Indices</a> </th> 28 29 <!-- Help link --> 30 <th> <a 31 href="help.html">Help</a> </th> 32 33 <th class="navbar" width="100%"></th> 34 </tr> 35</table> 36<table width="100%" cellpadding="0" cellspacing="0"> 37 <tr valign="top"> 38 <td width="100%"> 39 <span class="breadcrumbs"> 40 <a href="googleapiclient-module.html">Package googleapiclient</a> :: 41 Module sample_tools 42 </span> 43 </td> 44 <td> 45 <table cellpadding="0" cellspacing="0"> 46 <!-- hide/show private --> 47 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink" 48 onclick="toggle_private();">hide private</a>]</span></td></tr> 49 <tr><td align="right"><span class="options" 50 >[<a href="frames.html" target="_top">frames</a 51 >] | <a href="googleapiclient.sample_tools-pysrc.html" 52 target="_top">no frames</a>]</span></td></tr> 53 </table> 54 </td> 55 </tr> 56</table> 57<h1 class="epydoc">Source Code for <a href="googleapiclient.sample_tools-module.html">Module googleapiclient.sample_tools</a></h1> 58<pre class="py-src"> 59<a name="L1"></a><tt class="py-lineno"> 1</tt> <tt class="py-line"><tt class="py-comment"># Copyright 2014 Google Inc. All Rights Reserved.</tt> </tt> 60<a name="L2"></a><tt class="py-lineno"> 2</tt> <tt class="py-line"><tt class="py-comment">#</tt> </tt> 61<a name="L3"></a><tt class="py-lineno"> 3</tt> <tt class="py-line"><tt class="py-comment"># Licensed under the Apache License, Version 2.0 (the "License");</tt> </tt> 62<a name="L4"></a><tt class="py-lineno"> 4</tt> <tt class="py-line"><tt class="py-comment"># you may not use this file except in compliance with the License.</tt> </tt> 63<a name="L5"></a><tt class="py-lineno"> 5</tt> <tt class="py-line"><tt class="py-comment"># You may obtain a copy of the License at</tt> </tt> 64<a name="L6"></a><tt class="py-lineno"> 6</tt> <tt class="py-line"><tt class="py-comment">#</tt> </tt> 65<a name="L7"></a><tt class="py-lineno"> 7</tt> <tt class="py-line"><tt class="py-comment"># http://www.apache.org/licenses/LICENSE-2.0</tt> </tt> 66<a name="L8"></a><tt class="py-lineno"> 8</tt> <tt class="py-line"><tt class="py-comment">#</tt> </tt> 67<a name="L9"></a><tt class="py-lineno"> 9</tt> <tt class="py-line"><tt class="py-comment"># Unless required by applicable law or agreed to in writing, software</tt> </tt> 68<a name="L10"></a><tt class="py-lineno"> 10</tt> <tt class="py-line"><tt class="py-comment"># distributed under the License is distributed on an "AS IS" BASIS,</tt> </tt> 69<a name="L11"></a><tt class="py-lineno"> 11</tt> <tt class="py-line"><tt class="py-comment"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</tt> </tt> 70<a name="L12"></a><tt class="py-lineno"> 12</tt> <tt class="py-line"><tt class="py-comment"># See the License for the specific language governing permissions and</tt> </tt> 71<a name="L13"></a><tt class="py-lineno"> 13</tt> <tt class="py-line"><tt class="py-comment"># limitations under the License.</tt> </tt> 72<a name="L14"></a><tt class="py-lineno"> 14</tt> <tt class="py-line"> </tt> 73<a name="L15"></a><tt class="py-lineno"> 15</tt> <tt class="py-line"><tt class="py-docstring">"""Utilities for making samples.</tt> </tt> 74<a name="L16"></a><tt class="py-lineno"> 16</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt> 75<a name="L17"></a><tt class="py-lineno"> 17</tt> <tt class="py-line"><tt class="py-docstring">Consolidates a lot of code commonly repeated in sample applications.</tt> </tt> 76<a name="L18"></a><tt class="py-lineno"> 18</tt> <tt class="py-line"><tt class="py-docstring">"""</tt> </tt> 77<a name="L19"></a><tt class="py-lineno"> 19</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">__future__</tt> <tt class="py-keyword">import</tt> <tt class="py-name">absolute_import</tt> </tt> 78<a name="L20"></a><tt class="py-lineno"> 20</tt> <tt class="py-line"> </tt> 79<a name="L21"></a><tt class="py-lineno"> 21</tt> <tt class="py-line"><tt class="py-name">__author__</tt> <tt class="py-op">=</tt> <tt class="py-string">'jcgregorio@google.com (Joe Gregorio)'</tt> </tt> 80<a name="L22"></a><tt class="py-lineno"> 22</tt> <tt class="py-line"><tt class="py-name">__all__</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-string">'init'</tt><tt class="py-op">]</tt> </tt> 81<a name="L23"></a><tt class="py-lineno"> 23</tt> <tt class="py-line"> </tt> 82<a name="L24"></a><tt class="py-lineno"> 24</tt> <tt class="py-line"> </tt> 83<a name="L25"></a><tt class="py-lineno"> 25</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">argparse</tt> </tt> 84<a name="L26"></a><tt class="py-lineno"> 26</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">os</tt> </tt> 85<a name="L27"></a><tt class="py-lineno"> 27</tt> <tt class="py-line"> </tt> 86<a name="L28"></a><tt class="py-lineno"> 28</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Package googleapiclient=googleapiclient-module.html"><a title="googleapiclient" class="py-name" href="#" onclick="return doclink('link-0', 'googleapiclient', 'link-0');">googleapiclient</a></tt> <tt class="py-keyword">import</tt> <tt id="link-1" class="py-name" targets="Module googleapiclient.discovery=googleapiclient.discovery-module.html"><a title="googleapiclient.discovery" class="py-name" href="#" onclick="return doclink('link-1', 'discovery', 'link-1');">discovery</a></tt> </tt> 87<a name="L29"></a><tt class="py-lineno"> 29</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-2" class="py-name"><a title="googleapiclient" class="py-name" href="#" onclick="return doclink('link-2', 'googleapiclient', 'link-0');">googleapiclient</a></tt><tt class="py-op">.</tt><tt id="link-3" class="py-name" targets="Module googleapiclient.http=googleapiclient.http-module.html"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-3', 'http', 'link-3');">http</a></tt> <tt class="py-keyword">import</tt> <tt id="link-4" class="py-name" targets="Function googleapiclient.http.build_http()=googleapiclient.http-module.html#build_http"><a title="googleapiclient.http.build_http" class="py-name" href="#" onclick="return doclink('link-4', 'build_http', 'link-4');">build_http</a></tt> </tt> 88<a name="L30"></a><tt class="py-lineno"> 30</tt> <tt class="py-line"> </tt> 89<a name="init"></a><div id="init-def"><a name="L31"></a><tt class="py-lineno"> 31</tt> <a class="py-toggle" href="#" id="init-toggle" onclick="return toggle('init');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="googleapiclient.sample_tools-module.html#init">init</a><tt class="py-op">(</tt><tt class="py-param">argv</tt><tt class="py-op">,</tt> <tt class="py-param">name</tt><tt class="py-op">,</tt> <tt class="py-param">version</tt><tt class="py-op">,</tt> <tt class="py-param">doc</tt><tt class="py-op">,</tt> <tt class="py-param">filename</tt><tt class="py-op">,</tt> <tt class="py-param">scope</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">parents</tt><tt class="py-op">=</tt><tt class="py-op">[</tt><tt class="py-op">]</tt><tt class="py-op">,</tt> <tt class="py-param">discovery_filename</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt> 90</div><div id="init-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="init-expanded"><a name="L32"></a><tt class="py-lineno"> 32</tt> <tt class="py-line"> <tt class="py-docstring">"""A common initialization routine for samples.</tt> </tt> 91<a name="L33"></a><tt class="py-lineno"> 33</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt> 92<a name="L34"></a><tt class="py-lineno"> 34</tt> <tt class="py-line"><tt class="py-docstring"> Many of the sample applications do the same initialization, which has now</tt> </tt> 93<a name="L35"></a><tt class="py-lineno"> 35</tt> <tt class="py-line"><tt class="py-docstring"> been consolidated into this function. This function uses common idioms found</tt> </tt> 94<a name="L36"></a><tt class="py-lineno"> 36</tt> <tt class="py-line"><tt class="py-docstring"> in almost all the samples, i.e. for an API with name 'apiname', the</tt> </tt> 95<a name="L37"></a><tt class="py-lineno"> 37</tt> <tt class="py-line"><tt class="py-docstring"> credentials are stored in a file named apiname.dat, and the</tt> </tt> 96<a name="L38"></a><tt class="py-lineno"> 38</tt> <tt class="py-line"><tt class="py-docstring"> client_secrets.json file is stored in the same directory as the application</tt> </tt> 97<a name="L39"></a><tt class="py-lineno"> 39</tt> <tt class="py-line"><tt class="py-docstring"> main file.</tt> </tt> 98<a name="L40"></a><tt class="py-lineno"> 40</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt> 99<a name="L41"></a><tt class="py-lineno"> 41</tt> <tt class="py-line"><tt class="py-docstring"> Args:</tt> </tt> 100<a name="L42"></a><tt class="py-lineno"> 42</tt> <tt class="py-line"><tt class="py-docstring"> argv: list of string, the command-line parameters of the application.</tt> </tt> 101<a name="L43"></a><tt class="py-lineno"> 43</tt> <tt class="py-line"><tt class="py-docstring"> name: string, name of the API.</tt> </tt> 102<a name="L44"></a><tt class="py-lineno"> 44</tt> <tt class="py-line"><tt class="py-docstring"> version: string, version of the API.</tt> </tt> 103<a name="L45"></a><tt class="py-lineno"> 45</tt> <tt class="py-line"><tt class="py-docstring"> doc: string, description of the application. Usually set to __doc__.</tt> </tt> 104<a name="L46"></a><tt class="py-lineno"> 46</tt> <tt class="py-line"><tt class="py-docstring"> file: string, filename of the application. Usually set to __file__.</tt> </tt> 105<a name="L47"></a><tt class="py-lineno"> 47</tt> <tt class="py-line"><tt class="py-docstring"> parents: list of argparse.ArgumentParser, additional command-line flags.</tt> </tt> 106<a name="L48"></a><tt class="py-lineno"> 48</tt> <tt class="py-line"><tt class="py-docstring"> scope: string, The OAuth scope used.</tt> </tt> 107<a name="L49"></a><tt class="py-lineno"> 49</tt> <tt class="py-line"><tt class="py-docstring"> discovery_filename: string, name of local discovery file (JSON). Use when discovery doc not available via URL.</tt> </tt> 108<a name="L50"></a><tt class="py-lineno"> 50</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt> 109<a name="L51"></a><tt class="py-lineno"> 51</tt> <tt class="py-line"><tt class="py-docstring"> Returns:</tt> </tt> 110<a name="L52"></a><tt class="py-lineno"> 52</tt> <tt class="py-line"><tt class="py-docstring"> A tuple of (service, flags), where service is the service object and flags</tt> </tt> 111<a name="L53"></a><tt class="py-lineno"> 53</tt> <tt class="py-line"><tt class="py-docstring"> is the parsed command-line flags.</tt> </tt> 112<a name="L54"></a><tt class="py-lineno"> 54</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt> 113<a name="L55"></a><tt class="py-lineno"> 55</tt> <tt class="py-line"> <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt> 114<a name="L56"></a><tt class="py-lineno"> 56</tt> <tt class="py-line"> <tt class="py-keyword">from</tt> <tt class="py-name">oauth2client</tt> <tt class="py-keyword">import</tt> <tt class="py-name">client</tt> </tt> 115<a name="L57"></a><tt class="py-lineno"> 57</tt> <tt class="py-line"> <tt class="py-keyword">from</tt> <tt class="py-name">oauth2client</tt> <tt class="py-keyword">import</tt> <tt class="py-name">file</tt> </tt> 116<a name="L58"></a><tt class="py-lineno"> 58</tt> <tt class="py-line"> <tt class="py-keyword">from</tt> <tt class="py-name">oauth2client</tt> <tt class="py-keyword">import</tt> <tt class="py-name">tools</tt> </tt> 117<a name="L59"></a><tt class="py-lineno"> 59</tt> <tt class="py-line"> <tt class="py-keyword">except</tt> <tt class="py-name">ImportError</tt><tt class="py-op">:</tt> </tt> 118<a name="L60"></a><tt class="py-lineno"> 60</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt class="py-name">ImportError</tt><tt class="py-op">(</tt><tt class="py-string">'googleapiclient.sample_tools requires oauth2client. Please install oauth2client and try again.'</tt><tt class="py-op">)</tt> </tt> 119<a name="L61"></a><tt class="py-lineno"> 61</tt> <tt class="py-line"> </tt> 120<a name="L62"></a><tt class="py-lineno"> 62</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">scope</tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt> 121<a name="L63"></a><tt class="py-lineno"> 63</tt> <tt class="py-line"> <tt class="py-name">scope</tt> <tt class="py-op">=</tt> <tt class="py-string">'https://www.googleapis.com/auth/'</tt> <tt class="py-op">+</tt> <tt class="py-name">name</tt> </tt> 122<a name="L64"></a><tt class="py-lineno"> 64</tt> <tt class="py-line"> </tt> 123<a name="L65"></a><tt class="py-lineno"> 65</tt> <tt class="py-line"> <tt class="py-comment"># Parser command-line arguments.</tt> </tt> 124<a name="L66"></a><tt class="py-lineno"> 66</tt> <tt class="py-line"> <tt class="py-name">parent_parsers</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">tools</tt><tt class="py-op">.</tt><tt class="py-name">argparser</tt><tt class="py-op">]</tt> </tt> 125<a name="L67"></a><tt class="py-lineno"> 67</tt> <tt class="py-line"> <tt class="py-name">parent_parsers</tt><tt class="py-op">.</tt><tt class="py-name">extend</tt><tt class="py-op">(</tt><tt class="py-name">parents</tt><tt class="py-op">)</tt> </tt> 126<a name="L68"></a><tt class="py-lineno"> 68</tt> <tt class="py-line"> <tt class="py-name">parser</tt> <tt class="py-op">=</tt> <tt class="py-name">argparse</tt><tt class="py-op">.</tt><tt class="py-name">ArgumentParser</tt><tt class="py-op">(</tt> </tt> 127<a name="L69"></a><tt class="py-lineno"> 69</tt> <tt class="py-line"> <tt class="py-name">description</tt><tt class="py-op">=</tt><tt class="py-name">doc</tt><tt class="py-op">,</tt> </tt> 128<a name="L70"></a><tt class="py-lineno"> 70</tt> <tt class="py-line"> <tt class="py-name">formatter_class</tt><tt class="py-op">=</tt><tt class="py-name">argparse</tt><tt class="py-op">.</tt><tt class="py-name">RawDescriptionHelpFormatter</tt><tt class="py-op">,</tt> </tt> 129<a name="L71"></a><tt class="py-lineno"> 71</tt> <tt class="py-line"> <tt class="py-name">parents</tt><tt class="py-op">=</tt><tt class="py-name">parent_parsers</tt><tt class="py-op">)</tt> </tt> 130<a name="L72"></a><tt class="py-lineno"> 72</tt> <tt class="py-line"> <tt class="py-name">flags</tt> <tt class="py-op">=</tt> <tt class="py-name">parser</tt><tt class="py-op">.</tt><tt class="py-name">parse_args</tt><tt class="py-op">(</tt><tt class="py-name">argv</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">:</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt> 131<a name="L73"></a><tt class="py-lineno"> 73</tt> <tt class="py-line"> </tt> 132<a name="L74"></a><tt class="py-lineno"> 74</tt> <tt class="py-line"> <tt class="py-comment"># Name of a file containing the OAuth 2.0 information for this</tt> </tt> 133<a name="L75"></a><tt class="py-lineno"> 75</tt> <tt class="py-line"> <tt class="py-comment"># application, including client_id and client_secret, which are found</tt> </tt> 134<a name="L76"></a><tt class="py-lineno"> 76</tt> <tt class="py-line"> <tt class="py-comment"># on the API Access tab on the Google APIs</tt> </tt> 135<a name="L77"></a><tt class="py-lineno"> 77</tt> <tt class="py-line"> <tt class="py-comment"># Console <http://code.google.com/apis/console>.</tt> </tt> 136<a name="L78"></a><tt class="py-lineno"> 78</tt> <tt class="py-line"> <tt class="py-name">client_secrets</tt> <tt class="py-op">=</tt> <tt class="py-name">os</tt><tt class="py-op">.</tt><tt class="py-name">path</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-name">os</tt><tt class="py-op">.</tt><tt class="py-name">path</tt><tt class="py-op">.</tt><tt class="py-name">dirname</tt><tt class="py-op">(</tt><tt class="py-name">filename</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt> 137<a name="L79"></a><tt class="py-lineno"> 79</tt> <tt class="py-line"> <tt class="py-string">'client_secrets.json'</tt><tt class="py-op">)</tt> </tt> 138<a name="L80"></a><tt class="py-lineno"> 80</tt> <tt class="py-line"> </tt> 139<a name="L81"></a><tt class="py-lineno"> 81</tt> <tt class="py-line"> <tt class="py-comment"># Set up a Flow object to be used if we need to authenticate.</tt> </tt> 140<a name="L82"></a><tt class="py-lineno"> 82</tt> <tt class="py-line"> <tt class="py-name">flow</tt> <tt class="py-op">=</tt> <tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">flow_from_clientsecrets</tt><tt class="py-op">(</tt><tt class="py-name">client_secrets</tt><tt class="py-op">,</tt> </tt> 141<a name="L83"></a><tt class="py-lineno"> 83</tt> <tt class="py-line"> <tt class="py-name">scope</tt><tt class="py-op">=</tt><tt class="py-name">scope</tt><tt class="py-op">,</tt> </tt> 142<a name="L84"></a><tt class="py-lineno"> 84</tt> <tt class="py-line"> <tt class="py-name">message</tt><tt class="py-op">=</tt><tt class="py-name">tools</tt><tt class="py-op">.</tt><tt class="py-name">message_if_missing</tt><tt class="py-op">(</tt><tt class="py-name">client_secrets</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt> 143<a name="L85"></a><tt class="py-lineno"> 85</tt> <tt class="py-line"> </tt> 144<a name="L86"></a><tt class="py-lineno"> 86</tt> <tt class="py-line"> <tt class="py-comment"># Prepare credentials, and authorize HTTP object with them.</tt> </tt> 145<a name="L87"></a><tt class="py-lineno"> 87</tt> <tt class="py-line"> <tt class="py-comment"># If the credentials don't exist or are invalid run through the native client</tt> </tt> 146<a name="L88"></a><tt class="py-lineno"> 88</tt> <tt class="py-line"> <tt class="py-comment"># flow. The Storage object will ensure that if successful the good</tt> </tt> 147<a name="L89"></a><tt class="py-lineno"> 89</tt> <tt class="py-line"> <tt class="py-comment"># credentials will get written back to a file.</tt> </tt> 148<a name="L90"></a><tt class="py-lineno"> 90</tt> <tt class="py-line"> <tt class="py-name">storage</tt> <tt class="py-op">=</tt> <tt class="py-name">file</tt><tt class="py-op">.</tt><tt class="py-name">Storage</tt><tt class="py-op">(</tt><tt class="py-name">name</tt> <tt class="py-op">+</tt> <tt class="py-string">'.dat'</tt><tt class="py-op">)</tt> </tt> 149<a name="L91"></a><tt class="py-lineno"> 91</tt> <tt class="py-line"> <tt class="py-name">credentials</tt> <tt class="py-op">=</tt> <tt class="py-name">storage</tt><tt class="py-op">.</tt><tt id="link-5" class="py-name" targets="Method googleapiclient.discovery_cache.appengine_memcache.Cache.get()=googleapiclient.discovery_cache.appengine_memcache.Cache-class.html#get,Method googleapiclient.discovery_cache.base.Cache.get()=googleapiclient.discovery_cache.base.Cache-class.html#get,Method googleapiclient.discovery_cache.file_cache.Cache.get()=googleapiclient.discovery_cache.file_cache.Cache-class.html#get,Method googleapiclient.schema.Schemas.get()=googleapiclient.schema.Schemas-class.html#get"><a title="googleapiclient.discovery_cache.appengine_memcache.Cache.get 150googleapiclient.discovery_cache.base.Cache.get 151googleapiclient.discovery_cache.file_cache.Cache.get 152googleapiclient.schema.Schemas.get" class="py-name" href="#" onclick="return doclink('link-5', 'get', 'link-5');">get</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt> 153<a name="L92"></a><tt class="py-lineno"> 92</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">credentials</tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt> <tt class="py-keyword">or</tt> <tt class="py-name">credentials</tt><tt class="py-op">.</tt><tt class="py-name">invalid</tt><tt class="py-op">:</tt> </tt> 154<a name="L93"></a><tt class="py-lineno"> 93</tt> <tt class="py-line"> <tt class="py-name">credentials</tt> <tt class="py-op">=</tt> <tt class="py-name">tools</tt><tt class="py-op">.</tt><tt class="py-name">run_flow</tt><tt class="py-op">(</tt><tt class="py-name">flow</tt><tt class="py-op">,</tt> <tt class="py-name">storage</tt><tt class="py-op">,</tt> <tt class="py-name">flags</tt><tt class="py-op">)</tt> </tt> 155<a name="L94"></a><tt class="py-lineno"> 94</tt> <tt class="py-line"> <tt id="link-6" class="py-name"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-6', 'http', 'link-3');">http</a></tt> <tt class="py-op">=</tt> <tt class="py-name">credentials</tt><tt class="py-op">.</tt><tt class="py-name">authorize</tt><tt class="py-op">(</tt><tt id="link-7" class="py-name"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-7', 'http', 'link-3');">http</a></tt><tt class="py-op">=</tt><tt id="link-8" class="py-name"><a title="googleapiclient.http.build_http" class="py-name" href="#" onclick="return doclink('link-8', 'build_http', 'link-4');">build_http</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt> 156<a name="L95"></a><tt class="py-lineno"> 95</tt> <tt class="py-line"> </tt> 157<a name="L96"></a><tt class="py-lineno"> 96</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">discovery_filename</tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt> 158<a name="L97"></a><tt class="py-lineno"> 97</tt> <tt class="py-line"> <tt class="py-comment"># Construct a service object via the discovery service.</tt> </tt> 159<a name="L98"></a><tt class="py-lineno"> 98</tt> <tt class="py-line"> <tt class="py-name">service</tt> <tt class="py-op">=</tt> <tt id="link-9" class="py-name"><a title="googleapiclient.discovery" class="py-name" href="#" onclick="return doclink('link-9', 'discovery', 'link-1');">discovery</a></tt><tt class="py-op">.</tt><tt id="link-10" class="py-name" targets="Function googleapiclient.discovery.build()=googleapiclient.discovery-module.html#build"><a title="googleapiclient.discovery.build" class="py-name" href="#" onclick="return doclink('link-10', 'build', 'link-10');">build</a></tt><tt class="py-op">(</tt><tt class="py-name">name</tt><tt class="py-op">,</tt> <tt class="py-name">version</tt><tt class="py-op">,</tt> <tt id="link-11" class="py-name"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-11', 'http', 'link-3');">http</a></tt><tt class="py-op">=</tt><tt id="link-12" class="py-name"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-12', 'http', 'link-3');">http</a></tt><tt class="py-op">)</tt> </tt> 160<a name="L99"></a><tt class="py-lineno"> 99</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt> 161<a name="L100"></a><tt class="py-lineno">100</tt> <tt class="py-line"> <tt class="py-comment"># Construct a service object using a local discovery document file.</tt> </tt> 162<a name="L101"></a><tt class="py-lineno">101</tt> <tt class="py-line"> <tt class="py-keyword">with</tt> <tt class="py-name">open</tt><tt class="py-op">(</tt><tt class="py-name">discovery_filename</tt><tt class="py-op">)</tt> <tt class="py-keyword">as</tt> <tt class="py-name">discovery_file</tt><tt class="py-op">:</tt> </tt> 163<a name="L102"></a><tt class="py-lineno">102</tt> <tt class="py-line"> <tt class="py-name">service</tt> <tt class="py-op">=</tt> <tt id="link-13" class="py-name"><a title="googleapiclient.discovery" class="py-name" href="#" onclick="return doclink('link-13', 'discovery', 'link-1');">discovery</a></tt><tt class="py-op">.</tt><tt id="link-14" class="py-name" targets="Function googleapiclient.discovery.build_from_document()=googleapiclient.discovery-module.html#build_from_document"><a title="googleapiclient.discovery.build_from_document" class="py-name" href="#" onclick="return doclink('link-14', 'build_from_document', 'link-14');">build_from_document</a></tt><tt class="py-op">(</tt> </tt> 164<a name="L103"></a><tt class="py-lineno">103</tt> <tt class="py-line"> <tt class="py-name">discovery_file</tt><tt class="py-op">.</tt><tt id="link-15" class="py-name" targets="Method googleapiclient.http._StreamSlice.read()=googleapiclient.http._StreamSlice-class.html#read"><a title="googleapiclient.http._StreamSlice.read" class="py-name" href="#" onclick="return doclink('link-15', 'read', 'link-15');">read</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt> 165<a name="L104"></a><tt class="py-lineno">104</tt> <tt class="py-line"> <tt id="link-16" class="py-name" targets="Module googleapiclient.discovery_cache.base=googleapiclient.discovery_cache.base-module.html"><a title="googleapiclient.discovery_cache.base" class="py-name" href="#" onclick="return doclink('link-16', 'base', 'link-16');">base</a></tt><tt class="py-op">=</tt><tt class="py-string">'https://www.googleapis.com/'</tt><tt class="py-op">,</tt> </tt> 166<a name="L105"></a><tt class="py-lineno">105</tt> <tt class="py-line"> <tt id="link-17" class="py-name"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-17', 'http', 'link-3');">http</a></tt><tt class="py-op">=</tt><tt id="link-18" class="py-name"><a title="googleapiclient.http" class="py-name" href="#" onclick="return doclink('link-18', 'http', 'link-3');">http</a></tt><tt class="py-op">)</tt> </tt> 167<a name="L106"></a><tt class="py-lineno">106</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-op">(</tt><tt class="py-name">service</tt><tt class="py-op">,</tt> <tt class="py-name">flags</tt><tt class="py-op">)</tt> </tt> 168</div><a name="L107"></a><tt class="py-lineno">107</tt> <tt class="py-line"> </tt><script type="text/javascript"> 169<!-- 170expandto(location.href); 171// --> 172</script> 173</pre> 174<br /> 175<!-- ==================== NAVIGATION BAR ==================== --> 176<table class="navbar" border="0" width="100%" cellpadding="0" 177 bgcolor="#a0c0ff" cellspacing="0"> 178 <tr valign="middle"> 179 <!-- Home link --> 180 <th> <a 181 href="googleapiclient-module.html">Home</a> </th> 182 183 <!-- Tree link --> 184 <th> <a 185 href="module-tree.html">Trees</a> </th> 186 187 <!-- Index link --> 188 <th> <a 189 href="identifier-index.html">Indices</a> </th> 190 191 <!-- Help link --> 192 <th> <a 193 href="help.html">Help</a> </th> 194 195 <th class="navbar" width="100%"></th> 196 </tr> 197</table> 198<table border="0" cellpadding="0" cellspacing="0" width="100%%"> 199 <tr> 200 <td align="left" class="footer"> 201 Generated by Epydoc 3.0.1 on Fri Jun 14 15:57:29 2019 202 </td> 203 <td align="right" class="footer"> 204 <a target="mainFrame" href="http://epydoc.sourceforge.net" 205 >http://epydoc.sourceforge.net</a> 206 </td> 207 </tr> 208</table> 209 210<script type="text/javascript"> 211 <!-- 212 // Private objects are initially displayed (because if 213 // javascript is turned off then we want them to be 214 // visible); but by default, we want to hide them. So hide 215 // them unless we have a cookie that says to show them. 216 checkCookie(); 217 // --> 218</script> 219</body> 220</html> 221