Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Google Drive files are listed in Drive API request

I am trying to get a list of the files in my Google Drive using a desktop app. The code is as follows:

def main(argv):

    storage = Storage('drive.dat')
    credentials = storage.get()

    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage)

    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
    http = httplib2.Http()
    http = credentials.authorize(http)

    service = build("drive", "v2", http=http)
    retrieve_all_files(service)

Then in retrieve_all_files, I print the files:

param = {}
if page_token:
    param['pageToken'] = page_token
    files = service.files().list(**param).execute()
    print files

But after I authenticate to my account, the printed file list has no items. Does anyone have a similar problem or know of a solution to this?

like image 224
Robin W. Avatar asked Jul 31 '12 08:07

Robin W.


People also ask

Why is Google Drive not showing files?

Check Your Firewall and Proxy Settings Occasionally, firewall and proxy settings may block access to Google Drive. When you find the uploaded and shared files are not showing up in Google Drive, it is necessary to check your firewall and proxy settings.

How do I create a Google Drive folder in Google Drive API?

To create a folder, use the files. create method with the application/vnd. google-apps. folder MIME type and a title.

How do I get a list of files in Google Drive?

Create a new Google Sheets spreadsheet or open an existing spreadsheet where you want the list saved. Here's a tip: You can quickly create a new Google Sheets spreadsheet using https://spreadsheet.new. Create a sheet in the spreadsheet called "Files". The list of files will be written to the sheet.


1 Answers

Please correct me if I'm wrong but I believe you are using the https://www.googleapis.com/auth/drive.file scope, which only returns files that your app has created or have been explicitly opened with your app using the Google Drive UI or the Picker API.

To retrieve all files, you will need to use the broader scope: https://www.googleapis.com/auth/drive.

To learn more about the different scopes, have a look at the documentation.

like image 67
Alain Avatar answered Sep 25 '22 23:09

Alain