theprnce / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

files().insert seems to ignore parents parameter #298

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is with the Python library.

When I create a new file, the call seems to disregard the "parents" parameter. 
However, the documentation is a bit ambiguous about this parameter.

The documentation at 
https://developers.google.com/drive/v2/reference/files/insert says that it's a 
"list", and I've always assumed it was a list of IDs. However, the 
documentation at docs/dyn/drive_v2.files.html#insert weirdly says that its 
value should be something similar/identical to what is returned for parents 
from a get() request (an array of objects):

  "parents": [ # Collection of parent folders which contain this file.
      # Setting this field will put the file in all of the provided folders. On insert, if no folders are provided, the file will be placed in the default root folder.
    { # A reference to a file's parent.
      "selfLink": "A String", # A link back to this reference.
      "kind": "drive#parentReference", # This is always drive#parentReference.
      "id": "A String", # The ID of the parent.
      "isRoot": True or False, # Whether or not the parent is the root folder.
      "parentLink": "A String", # A link to the parent.
    },
  ],

This doesn't seem like the correct parameter for an insert operation. "kind" 
and "isRoot" can be readily derived by the backend, and not only does it seem 
weird to be providing links ("selfLink", "parentLink") -for- Google -to- 
Google, but I can't possibly provide "selfLink" prior to having the ID for the 
new file. Obviously, it also seems like there's a documentation bug.

These are the parameters going into insert():

{'body': {'mimeType': 'application/octet-stream', 'description': None, 'title': 
u'ad', 'labels': {'hidden': False}, 'lastViewedByMeDate': 
'2013-08-21T06:11:23.296336+00:00', 'parents': 
[u'0B5Ft2OXeDBqSTk95M3VHSEY0eEk'], 'modifiedDate': 
'2013-08-21T06:11:23.296336+00:00'}, 'media_body': 
<apiclient.http.MediaFileUpload object at 0xb6cead0c>}

Notice that the new file has parents [u'0B5Ft2OXeDBqSTk95M3VHSEY0eEk'].

The new file is given ID 0B5Ft2OXeDBqSSE9iR2MyNENZbnc.

In the OAuth Playground, I do a files.get, and see the following:

 "title": "ad",
 "parents": [
  {
   "kind": "drive#parentReference",
   "id": "0AJFt2OXeDBqSUk9PVA",
   "selfLink": "https://www.googleapis.com/drive/v2/files/0B5Ft2OXeDBqSSE9iR2MyNENZbnc/parents/0AJFt2OXeDBqSUk9PVA",
   "parentLink": "https://www.googleapis.com/drive/v2/files/0AJFt2OXeDBqSUk9PVA",
   "isRoot": true
  }
 ],

The parent ID 0AJFt2OXeDBqSUk9PVA is that of my root folder.

I've tried with both my original version of the client (a couple of versions 
behind), 1.2, and a current clone from Mercurial.

It seems like, if either the Python library or the backend were broken, a lot 
of people would know about it. Therefore, I must be missing something.

Thanks.

Dustin

Original issue reported on code.google.com by myselfasunder@gmail.com on 22 Aug 2013 at 2:39

GoogleCodeExporter commented 9 years ago
Note that in the documentation you link to above, and in this documentation 
below, that the parents parameter is not a list of parent ids, but instead is a 
list of objects, and each object contains a parent id.

 body = {
    'title': title,
    'description': description,
    'mimeType': mime_type,
    'parents' = [{'id': parent_id}]
  }

See the Python code on this page:

  https://developers.google.com/drive/v2/reference/files/insert

Original comment by jcgregorio@google.com on 22 Aug 2013 at 10:30

GoogleCodeExporter commented 9 years ago
I'd still like to request that the packaged documentation be corrected 
according to the above.

I'd also suggest that Google update their documentation styles to allow for new 
types "listofscalars" and "listofobjects" to give the developer more of a hint 
than simply "list", in the event that there are no relevant examples. However, 
this isn't the right forum for that.

Original comment by myselfasunder@gmail.com on 22 Aug 2013 at 8:29