You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are many methods to create and update file metadata and contents. With *PyDrive2*, all you have to know is
41
41
`Upload()`_ method which makes optimal API call for you. Add the following code to your *quickstart.py* and run it.
@@ -57,8 +57,8 @@ This code will create a new file with title *Hello.txt* and its content *Hello W
57
57
.. _`Google Drive`: https://drive.google.com
58
58
.. _`File management made easy`: ./filemanagement.html
59
59
60
-
Getting list of files
61
-
---------------------
60
+
Listing Files
61
+
-------------
62
62
63
63
*PyDrive2* handles paginations and parses response as list of `GoogleDriveFile`_. Let's get title and id of all the files in the root folder of Google Drive. Again, add the following code to *quickstart.py* and execute it.
64
64
@@ -84,23 +84,26 @@ GoogleDrive treats everything as a file and assigns different mimetypes for diff
84
84
return newFolder
85
85
86
86
87
-
Get Id of the title
88
-
-------------------
87
+
Return File ID via File Title
88
+
-----------------------------
89
89
90
-
``get_id_of_title`` is a function that return id of the given title's file in the directory.
90
+
A common task is providing the Google Drive API with a file id.
91
+
``get_id_of_title`` demonstrates a simple workflow to return the id of a file handle by searching the file titles in a
92
+
given directory. The function takes two arguments, ``title`` and ``parent_directory_id``. ``title`` is a string that
93
+
will be compared against file titles included in a directory identified by the ``parent_directory_id``.
91
94
92
95
.. code-block:: python
93
96
94
97
defget_id_of_title(title,parent_directory_id):
95
98
foldered_list=drive.ListFile({'q': "'"+parent_directory_id+"' in parents and trashed=false"}).GetList()
96
99
forfilein foldered_list:
97
-
if(file['title']==title):
98
-
returnfile['id']
99
-
returnNone
100
+
if(file['title']==title):
101
+
returnfile['id']
102
+
returnNone
100
103
101
-
folder browser
104
+
Browse Folders
102
105
--------------
103
-
This return a json output of the data in the directory with some important attributes like size, title, parent_id etc
106
+
This returns a json output of the data in a directory with some important attributes like size, title, parent_id.
104
107
105
108
.. code-block:: python
106
109
@@ -136,7 +139,7 @@ This return a json output of the data in the directory with some important attri
136
139
137
140
here ``folder_list``is the list of folders that is present
138
141
139
-
You will see title andid of all the files and folders in root folder of your Google Drive. For more details, take a look at documentation: `File listing made easy`_
142
+
You will see title andid of all the files and folders in root folder of your Google Drive. For more details, refer to the documentation: `File listing made easy`_
<p>Run this code with <em>python quickstart.py</em> and you will see a web browser asking you for authentication. Click <em>Accept</em> and you are done with authentication. For more details, take a look at documentation: <aclass="reference external" href="./oauth.html">OAuth made easy</a></p>
<h2>Creating and Updating Files<aclass="headerlink" href="#creating-and-updating-files" title="Permalink to this headline">¶</a></h2>
203
203
<p>There are many methods to create and update file metadata and contents. With <em>PyDrive2</em>, all you have to know is
204
204
<aclass="reference external" href="./pydrive2.html#pydrive2.files.GoogleDriveFile.Upload">Upload()</a> method which makes optimal API call for you. Add the following code to your <em>quickstart.py</em> and run it.</p>
@@ -216,8 +216,8 @@ <h2>Creating and updating file<a class="headerlink" href="#creating-and-updating
216
216
</dd>
217
217
</dl>
218
218
</div>
219
-
<divclass="section" id="getting-list-of-files">
220
-
<h2>Getting list of files<aclass="headerlink" href="#getting-list-of-files" title="Permalink to this headline">¶</a></h2>
219
+
<divclass="section" id="listing-files">
220
+
<h2>Listing Files<aclass="headerlink" href="#listing-files" title="Permalink to this headline">¶</a></h2>
221
221
<p><em>PyDrive2</em> handles paginations and parses response as list of <aclass="reference external" href="./pydrive2.html#pydrive2.files.GoogleDriveFile">GoogleDriveFile</a>. Let’s get title and id of all the files in the root folder of Google Drive. Again, add the following code to <em>quickstart.py</em> and execute it.</p>
222
222
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># Auto-iterate through all files that matches this query</span>
223
223
<spanclass="n">file_list</span><spanclass="o">=</span><spanclass="n">drive</span><spanclass="o">.</span><spanclass="n">ListFile</span><spanclass="p">({</span><spanclass="s1">'q'</span><spanclass="p">:</span><spanclass="s2">"'root' in parents and trashed=false"</span><spanclass="p">})</span><spanclass="o">.</span><spanclass="n">GetList</span><spanclass="p">()</span>
@@ -240,21 +240,24 @@ <h2>Creating a Folder<a class="headerlink" href="#creating-a-folder" title="Perm
240
240
</pre></div>
241
241
</div>
242
242
</div>
243
-
<divclass="section" id="get-id-of-the-title">
244
-
<h2>Get Id of the title<aclass="headerlink" href="#get-id-of-the-title" title="Permalink to this headline">¶</a></h2>
245
-
<p><codeclass="docutils literal notranslate"><spanclass="pre">get_id_of_title</span></code> is a function that return id of the given title’s file in the directory.</p>
<h2>Return File ID via File Title<aclass="headerlink" href="#return-file-id-via-file-title" title="Permalink to this headline">¶</a></h2>
245
+
<p>A common task is providing the Google Drive API with a file id.
246
+
<codeclass="docutils literal notranslate"><spanclass="pre">get_id_of_title</span></code> demonstrates a simple workflow to return the id of a file handle by searching the file titles in a
247
+
given directory. The function takes two arguments, <codeclass="docutils literal notranslate"><spanclass="pre">title</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">parent_directory_id</span></code>. <codeclass="docutils literal notranslate"><spanclass="pre">title</span></code> is a string that
248
+
will be compared against file titles included in a directory identified by the <codeclass="docutils literal notranslate"><spanclass="pre">parent_directory_id</span></code>.</p>
<spanclass="n">foldered_list</span><spanclass="o">=</span><spanclass="n">drive</span><spanclass="o">.</span><spanclass="n">ListFile</span><spanclass="p">({</span><spanclass="s1">'q'</span><spanclass="p">:</span><spanclass="s2">"'"</span><spanclass="o">+</span><spanclass="n">parent_directory_id</span><spanclass="o">+</span><spanclass="s2">"' in parents and trashed=false"</span><spanclass="p">})</span><spanclass="o">.</span><spanclass="n">GetList</span><spanclass="p">()</span>
<p>here <codeclass="docutils literal notranslate"><spanclass="pre">folder_list</span></code> is the list of folders that is present</p>
290
-
<p>You will see title and id of all the files and folders in root folder of your Google Drive. For more details, take a look at documentation: <aclass="reference external" href="./filelist.html">File listing made easy</a></p>
293
+
<p>You will see title and id of all the files and folders in root folder of your Google Drive. For more details, refer to the documentation: <aclass="reference external" href="./filelist.html">File listing made easy</a></p>
0 commit comments