As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
Create a Token for a user.
Click on Site administration ► Plugins ► Web services ► Manage tokens
Configure your site to use the Google Oauth: https://docs.moodle.org/dev/OAuth2_Services .
Enable the Google Drive repository and assign the Google OAuth 2 service to it.
Make sure to set " Supported files " to " Internal and External " and " Default return type " to " External (only links stored in Moodle) "
Now go back to to Site administration > Server > OAuth 2 Services and connect a system account for the Google OAuth 2 service.
Create a course and enrol the user from step 2.
Create a File resource from the Google Drive repository. Make sure to select " Create an access controlled link to the file " and set Display to Embed .
Open the File resource, inspect the page and copy the URL from the iframe. It should be something like this:
https://YOURSITE/pluginfile.php/180/mod_resource/content/2/File.gdoc
Now you'll have to modify the URL you copied in the previous step. Add webservice/ right before pluginfile.php, and also add the user token as a param at the end. Using the example for the previous step:
https://YOURSITE/webservice/pluginfile.php/180/mod_resource/content/2/File.gdoc?token=2155003aac9cf435ac186fb9c64fec39
Open this URL in a browser. You should get this error:
{"error":"Unsupported redirect detected, script execution terminated","errorcode":"redirecterrordetected","stacktrace":null,"debuginfo":null,"reproductionlink":null}
Now add &offline=1 at the end of the URL and try again. Now the file should be displayed or downloaded (depending on the extension)
MDL-58334 and MDL-32471 introduced new parameters in pluginfile.php but they are missing from webservice/pluginfile.php
We need the offline one in the Mobile app (this new parameter was designed thinking in the mobile app)