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?
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.
To create a folder, use the files. create method with the application/vnd. google-apps. folder MIME type and a title.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With