Upload File Google Drive Php

This is the second article in the drive series for web programmers that aims to explain how to use the Google Drive API in your web applications to access files/folders on behalf of your logged-in users. One of the basic tasks here is to authenticate to google and access the drive on the user’s behalf once they grant permission to your app.

  1. Google Drive Upload Link

Jun 06, 2015  Uploading Folders to Google Drive. Methods 1 and 2 use Google Chrome as the web browser. Method 3 explores using another web browser. Click on the “NEW” button. Click on “Folder upload”. Select the desired folder. Click the “OK” button.

This method of authentication is called and is very much needed for implementing the drive api. However, a good documentation to implement this in a backend app, especially a php app is very much lacking.

DriveFile

The so called and the web based example show some example code, but what a lot of beginner programmers need is a step-by-step tutorial of how to go about doing it. I: Register a google app by visiting the: The way the latest version (V3) of drive API works is only through OAuth. It means you cannot put a password or API key inside your code and access the drive files. You need to register your backend app and generate OAuth credentials for the app, so that it can access the drive on the user’s behalf once the user grants permission to the app.

So the first step is going to the, registering the app itself and generating OAuth credentials. The registration process is pretty straightforward, we just select “Create Project” from the dropdown and give a nice name for the project such as Drive Example App in our case. II: Configure the credentials and download the clientid.json file: This is the credential file that validates to Google who you are (as a developer) and also your app that acts on your behalf. Download and save it as clientid.json in the same directory as your app. III: Write your back-end app: First of all, you have to add the dependency of google-api php library to your project. If you are using composer, all you need to do is add this package to the composer.json.

I have difficulties in setting custom properties in file upload at google drive api using php. Uploading the file is ok, but, I can't set custom properties name.

I have check in their official documentation. But, I can't find it. Below are my upload codes. I also asked in.

But, I didn't get the answers. Could anyone help me about that.

$fileMetadata = new GoogleServiceDriveDriveFile; $fileMetadata-setName( 'app property test' ); $fileMetadata-setProperties( jsonencode( array( 'key' = 'customkey', 'value' = 'This is value', 'visibility' = 'PRIVATE', ) ) ); $content = filegetcontents( $filepath ); $file = $service-files-create( $fileMetadata, array( 'data' = $content, 'mimeType' = $mimeType, 'uploadType' = 'multipart', ) ); here is some of the things that I have already tested. //This one doesn't work too $fileMetadata-setProperties(array( 'key' = 'customkey', 'value' = 'This is value', 'visibility' = 'PRIVATE', )); I also tested with this one, too. //this is not working $fileMetadata = new GoogleServiceDriveDriveFile(array( 'name' = 'This is file name', 'appProperties' = array( 'mycustomfield' = 'My value' ) )); Could anyone advice me how I should set custom properties in google drive upload files.