Google API Project and Google Chrome extension

First, you need to register your application as an API Project in Google's API Console, and enable the "Drive API" and "Drive SDK" services.

In the "API Access" section, generate an OAuth 2.0 client ID (choose "Web application", and enter the URL of the web application). This should provide a client ID, a client secret, and a URI to which OAuth authentication requests will redirect after confirmation.

In the "Drive SDK" section, fill in all the required information. Use the client ID generated above for the "OAuth Client ID" field. I'm not sure exactly which scopes are needed here, but I've entered "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/userinfo.email" and "https://www.googleapis.com/auth/userinfo.profile".

Next, the App ID from the top of the "Drive SDK" section needs to be added to a Chrome extension. Create a Google Chrome extension for your web application, including the settings "container": "GOOGLE_DRIVE" and "api_console_project_id" (the App ID) in its manifest.json, and publish it on the Chrome Web Store.

When a user installs this Chrome extension, the web application asks for permission to access the user's Google Drive space.

Visit that URL in a web browser, and confirm that the web application is allowed to access your Google Drive files. Copy the code from the end of the URL to which you are redirected after confirmation, and use it as $_GET['code'] to retrieve an access token: