theprnce / google-api-python-client

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

Service account gives wrong answers for valid Google Drive file searches. #283

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[Use this form for both apiclient and oauth2client issues]

What steps will reproduce the problem?

1. Choose or create a folder shared publicly that has documents in it (either 
from a regular google account or from a google apps account)

2. In google-drive-sdk, use either an API key or service account to build the 
service. (I used a google apps for education account to do this, if that 
matters).

3. Search for files using various valid queries:

param = {'q':q}   # where q is like "'<folder_id>' in parents and mimetype...

files = service.files().list(**param).execute()

Note: I have minimal executable code that demonstrates the issue posted on 
pastebin:

http://pastebin.com/HaXyVADL 

What is the expected output? What do you see instead?

Take these four queries:

q1 = "'%s' in parents and trashed = false" % public_root
q2 = "'%s' in parents and mimeType = 'application/vnd.google-apps.folder'" % 
public_root

q3 = "'%s' in parents and fullText contains 'legally'" % public_root
q4 = "'%s' in parents and mimeType = 'application/vnd.google-apps.document'" % 
public_root

What I expect to see is actually seen when I use the flow authorization method 
detailed in the quickstart, using an account that is unrelated to the folder's 
owner.  The number of results returned by these queries are

q1 = 4
q2 = 1
q3 = 1
q4 = 3

However, when I use a service account (see pastebin file for details) I get:

q1 = 4
q2 = 1
q3 = 0
q4 = 0

And when I use an API key (again, see pastebin):

q1 = 4
q2 = 1

Traceback (most recent call last):
  File "g-drive-auth.py", line 90, in <module>
    files = service.files().list(**param).execute()
  File "/usr/local/lib/python2.6/dist-packages/google_api_python_client-1.1-py2.6.egg/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/google_api_python_client-1.1-py2.6.egg/apiclient/http.py", line 680, in execute
    raise HttpError(resp, content, uri=self.uri)
apiclient.errors.HttpError: <HttpError 500 when requesting 
https://www.googleapis.com/drive/v2/files?q=%270B9fHIF1yl5iqOHhSSS1BN1hRblE%27+i
n+parents+and+fullText+contains+%27legally%27&alt=json&key=AIzaSyB4EHJp9gIiESzn4
IhbsfbRolSuy625nok returned "Internal Error">

q4 also causes the same error.

What version of the product are you using? On what operating system?

apiclient version 1.1
oauth2client version 1.1
python 2.6.5
ubuntu 10.04

Please provide any additional information below.

My intention is to use the google drive sdk to show parts of files that are 
owned by a google apps for education account on a website.  I could just grab 
the plain text of every file and do the search in python, but these queries 
should work. right?

Original issue reported on code.google.com by offonoff...@gmail.com on 19 Jun 2013 at 7:25

GoogleCodeExporter commented 9 years ago
For the service account, did you add share all the documents with the email 
address you have stored in local.serviceaccountemail?

Original comment by jcgregorio@google.com on 19 Jun 2013 at 7:45

GoogleCodeExporter commented 9 years ago
I had not done that and doing so fixes the issue.

Original comment by offonoff...@gmail.com on 19 Jun 2013 at 8:46

GoogleCodeExporter commented 9 years ago
Thanks! This isn't expected behavior to me (that some searches would be fine 
and some wouldn't), but the way to get correct behavior is simple.

Original comment by offonoff...@gmail.com on 19 Jun 2013 at 9:07

GoogleCodeExporter commented 9 years ago

Original comment by jcgregorio@google.com on 20 Jun 2013 at 1:34